PDA

View Full Version : What is wrong with this code?



lindm
09-14-2007, 02:45 PM
THis code works locally on when testing in my browser, but when uploaded to a webhost stops to function...


function validateform(){

if (!(form.BRtsumcy.value == form.BRekssumcy.value))
{alert ("hello");}

}


<input name="check" type="button" class="px10" id="check" onclick="validateform()" value="Kontroll" />

boogyman
09-14-2007, 03:06 PM
if (!(form.BRtsumcy.value == form.BRekssumcy.value))


why not


if (form.BRtsumcy.value != form.BRekssumcy.value)


and as for why its not working, you most likely will need to show us more of your code as that alone will not help us determine if you have your declarations correct.

Twey
09-14-2007, 03:47 PM
No, we need to see the form and all its elements. You should, however, be accessing them as document.forms.form.elements.BRtsumcy.value rather than form.BRtsumcy.value. The latter is heavily deprecated and probably won't even work in a lot of cases.

lindm
09-14-2007, 05:04 PM
Ok, narrowed it down a part of my function:


if(document.forms[form.NOTekUBtot]){if (form.BReksumcy.value != form.NOTekUBtot.value)
{
alerttxt += "Hello3\n\n";
}}
This part is supposed to be executed if there is an element called form.NOTekUBtot...but not working? Anyone of you see the error?

Whole function

function validateform(){
var alerttxt="";
if (form.BRtsumcy.value != form.BRekssumcy.value||form.BRtsumpy.value != form.BRekssumpy.value)
{
alerttxt += "Hello1\n\n";
}
if (form.RRarescy.value != form.BRekAREScy.value||form.RRarespy.value != form.BRekARESpy.value)
{
alerttxt += "Hello2\n\n";
}
if(document.forms[form.NOTekUBtot]){if (form.BReksumcy.value != form.NOTekUBtot.value)
{
alerttxt += "Hello3\n\n";
}}

if (alerttxt){
alert(alerttxt);
return false;
}
return true;

}

lindm
09-14-2007, 05:17 PM
Alright think I got that part right. New code:


if(document.getElementById("NOTekUBtot")){if (document.forms.form.elements.BReksumcy.value != document.forms.form.elements.NOTekUBtot.value)
{
alerttxt += "Hello3\n\n";
}}


Found an alternative to if(document.getElementById("NOTekUBtot")) in the shape of using eval(), no luck on getting this one to work though. Any thoughts on if I should try to use eval() instead?

Twey
09-14-2007, 06:28 PM
This part is supposed to be executed if there is an element called form.NOTekUBtot...but not working? Anyone of you see the error?There is no element named form.NOTekUBtot. Neither is there a form named form.NOTekUBtot (or rather, the value of form.NOTekUBtot) which is what you're asking in the above code. I think you mean document.forms.form.elements.NOTekUBtot.