![]() |
Are Operators Valid?
Hey,
Quick question. My site currently has 4 invalid HTML errors. It's all down to this function: Code:
// Error checkingI'm guessing it's my code, perhaps it's not wrote out correctly, though it does work. Does anybody have any suggestions? BTW: I'm using PrototypeJS Cheers, - Chris. |
&& in that context seems totally wrong. You're assigning the values and && is for checking, such as like: if kiwi is kiwi AND banana is banana. If you're attempting to concatenate the values then the plus symbol is the way to go with javascript:
Code:
valid = $(this.to).present() + $(this.subject).present() + $(this.message).present(); |
No, in this case the
&& is correct. If you look at the code, it's checking if various fields are 'present' and assigning the valid variable if they all are.The HTML validation errors are caused by the ampersands (&) in your JavaScript but you should not change them to anything else. Instead, it is advisable (not just because of validation) to put your JavaScript in its own file and reference it using a <script> HTML element. |
Im not sure present is a function in Protoype, try changing
present() to empty(), you'll have to negate each condition too.Code:
valid = !$(this.to).empty() && !$(this.subject).empty() && !$(this.message).empty(); |
I think having the code in an external file, or maybe even just between the <head> tags might change the outcome.
Karl, hi... present() is a Form Element in Prototype. It has an example code, which I pretty much copied, but used an alert() instead of displaying some text. See the document (http://www.prototypejs.org/api/form/element/present) |
If you're wanting to keep the code within the HTML document, you'll need to tell the validator not to check the script by making it a CDATA block (that's XML terminology). The two "commented" (
//) lines are what's important here.HTML Code:
<script type="text/javascript"> |
Cool, I'll have a stab at it.
Cheers. |
I've never been a big fan of CDATA as I think it looks somewhat messy, but it serves a purpose so why the hell not :) ! Everything in external files, for me.
|
| All times are GMT. The time now is 04:21 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0