Results 1 to 6 of 6

Thread: What is wrong with this code?

  1. #1
    Join Date
    Jun 2007
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default What is wrong with this code?

    THis code works locally on when testing in my browser, but when uploaded to a webhost stops to function...

    Code:
    function validateform(){
    
    	if (!(form.BRtsumcy.value == form.BRekssumcy.value))
    	{alert ("hello");}
    	
    	}
    Code:
    <input name="check" type="button" class="px10" id="check" onclick="validateform()" value="Kontroll" />

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    if (!(form.BRtsumcy.value == form.BRekssumcy.value))
    why not
    Code:
    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.

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Jun 2007
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok, narrowed it down a part of my function:

    Code:
    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
    Code:
    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;
    
    }

  5. #5
    Join Date
    Jun 2007
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Alright think I got that part right. New code:

    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?

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •