Web Analytics Made Easy -
StatCounter Variables and HTML Forms - CodingForum

Announcement

Collapse
No announcement yet.

Variables and HTML Forms

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Variables and HTML Forms

    Currently I have the following script:-

    Code:
    function validate_form(){
        if(regform.reguser.value == ""){
    	  alert("Please completed the selected box");
    	  regform.reguser.focus();
    	  return false;  
        }else if(regform.regemail.value == ""){
          alert("Please completed the selected box");
    	  regform.regemail.focus();
    	  return false;
    	}else if(regform.regpass1.value == ""){
    	  alert("Please completed the selected box");
    	  regform.regpass1.focus();
    	  return false;
        }else if(regform.regpass2.value == ""){
    	  alert("Please completed the selected box");
          regform.regpass2.focus();	  
    	  return false;
    	}else{	
          return true;
    	}
    }
    to validate a simple registration form, however I initially tried to streamline this function by cycling through an array using a loop to point to various input elements in the HTML page itself. I found that when trying to use a variable in the aforementioned if statements the javascript failed to work i.e.

    Code:
    var test = "reguser";
    if(regform.test.value = ""){
    }
    I know the javascript is looking for the input element "test" instead of "reguser" but is there any way I can force it to look for the contents of the variable.

  • #2
    Code:
    regform.elements[test].value
    Glenn
    vBulletin Mods That Rock!

    Comment


    • #3
      Code:
      var test = "reguser";
      if(regform[test].value = ""){  ... }
      EDIT: Oh, man! THREE minutes. I really am slowing down!
      Be yourself. No one else is as qualified.

      Comment

      Working...
      X
      😀
      🥰
      🤢
      😎
      😡
      👍
      👎