Results 1 to 3 of 3

Thread: Check multiple text box input

  1. #1
    Join Date
    Nov 2009
    Posts
    518

    Check multiple text box input

    Hi
    I am trying an javascript program that has four fields in a form, the condition is that they should not be empty on submit. My plain is to make an array that check them, but this is not worked for me yet. I have posted my code below please check it, any advice or suggestion will be appreciated. Thanks
    Code:
            <form action="login.php" method="post" onsubmit="return(checkAll(this))">
          <label>Username<br /><input id="input[]" type="text" name="username" /></label><br />
          <label>Email<br /><input id="input[]" type="text" name="email" /></label><br />
          <label>Password<br /><input id="input[]" type="password" name="pswd1" /></label><br />
          <label>Password Again<br /><input id="input[] "type="password" name="pswd2" /></label><br />
          <input type="submit" name="submit" value="Submit" />
          <input type="reset" value="Reset" />
          </form>

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Check multiple text box input

    Hello
    Ok, i think it is good that you give the fields a unique id's. If the fields are not increasing any time or they are not going to change, then you can just create a if else statement. And if the fields are going to increase you can handle them from the loop. But before that you have to determine the length of each field in the form. I am posting a code below, I am not sure this will help you or not. But still just go through it.
    Code:
    var fr1 = document.forms[formName]
    //formName being the name of the form
    for (i = 0; i < fr1 .length; i++) {
    inp= fr1 .elements[i];
    if (inp.value.length == 0){
    alert("Please enter value in field" + inp.name);
    If any help needed then you can post back again.

  3. #3
    Join Date
    Nov 2009
    Posts
    518

    Re: Check multiple text box input

    Hi
    Thanks for your post. But it is something weird, when I wrote the code by the name it worked. I have posted the code below.
    Code:
    unction chall(formObj)
    {
    	alert("formObj here");
    	chob = document.getElementsByName("input[]");
    	alert("formObj here1");
    for (i=0; i<chob.length; i++)
    	{
    		alert("inside formObj here");
    	  if (chob[i].value == "")
    	  {
    	alert("Input item on Row #"+(i+1)+" has been left empty. Please make sure you input something into this field.");
    		return false;
    	  }
    }
    But when I change the code and write it by ID, it does not work. any ideas or suggestions.
    Code:
    function chall(formObj)
    {
    	alert("formObj here");
    	alert("formObj here");
    	chob = document.getElementsById("input[]");
    	alert("formObj here1");
    
    	for (i=0; i<chob.length; i++)
    	{
    		alert("inside formObj here");
    
    	  if (chob[i].value == "")
    	  {
    		alert("Input item on Row #"+(i+1)+" has been left empty. Please make sure you input something into this field.");
    		return false;
    	  }
    }

Similar Threads

  1. Input text value problem
    By NetworkeR in forum Software Development
    Replies: 3
    Last Post: 28-11-2009, 11:56 AM
  2. How to check input if it is number or not?
    By Linoo in forum Software Development
    Replies: 3
    Last Post: 24-11-2009, 04:46 PM
  3. Setting input text values
    By Solaris in forum Software Development
    Replies: 3
    Last Post: 23-11-2009, 02:42 PM
  4. Optical audio multiple input
    By MAURO in forum Portable Devices
    Replies: 3
    Last Post: 25-08-2009, 01:47 PM

Tags for this Thread

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
  •  
Page generated in 1,714,135,404.14362 seconds with 17 queries