Click to See Complete Forum and Search --> : help needed


mango
08-05-2005, 09:48 AM
cannot get the following form validation to work, any ideas:

the top of the form is:
<form action="index.cfm" method="post" id="marketingprFormedit" name="emailsig_form" onsubmit="return chkemailsignature();">


javascript is

function chkemailsignature() {
thisForm = document.getElementById("marketingprFormedit");
var errorinfo = "";
var retval = true;

if (thisForm.html_sig.value == 0 && !thisForm.html_sig.value.length) {
retval = false;
errorinfo += "\n * Please complete the html E-mail signature in the upper edit field.\n";
}
if (thisForm.text_sig.value == 0 && !thisForm.text_sig.value.length) {
retval = false;
errorinfo += "\n * Please complete the text E-mail signature in the lower edit field.\n";
}
if (thisForm.title.value == 0 && !thisForm.title.value.length) {
retval = false;
errorinfo += "\n * Please give this E-mail signature a title.\n";
}

return retval;
}




many thanks

A1ien51
08-05-2005, 10:35 AM
Read you logic outload when you write it

thisForm.html_sig.value == 0 && !thisForm.html_sig.value.length

"if this equals zero and has no length then show error"

Can you spot your error by reading it out loud?

Eric

mango
08-05-2005, 10:37 AM
equals zero and has no length ..... i did try it first without the equals zero, but still did not work...

Kor
08-05-2005, 10:43 AM
More than that
1.
an element value is a string, not a number, so that maybe you wanna say
thisForm.html_sig.value=='0'
2.
the lenght of a value , if set, always exists (if nothing is input, the value is 0), so probably you wanna say:
thisForm.html_sig.value.length==0

if, so, the correct ideea should be something like:

if (thisForm.html_sig.value == '0' && thisForm.html_sig.value.length==0)

mango
08-05-2005, 10:50 AM
Kor thanks for that, but I thought that '!thisForm.html_sig.value.length' meant that 'not if this form length'....same as saying ==0, does it?

Kor
08-05-2005, 11:03 AM
no

the existence of a property and the length of a property are different things. First is a boolean (the values are true/false), second is an integer classical arithmetic value.

Well, yes, the interpretor is instructed to assimilate false with 0, but only in special cases. There is no use to complicate. I think it is enough to condition the length of the value to 0

if (thisForm.html_sig.value.length==0)

A1ien51
08-05-2005, 11:40 AM
My comment was how can a form element have a length of zero and also have value of zero?

Kor
08-08-2005, 02:57 AM
My comment was how can a form element have a length of zero and also have value of zero?
Yes, I got it. ;) I have just wanted to clear up the elementary notions for mango to understand better the error.