Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 24-11-2009
Member
 
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>
Reply With Quote
  #2  
Old 24-11-2009
Member
 
Join Date: Jan 2008
Posts: 1,515
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.
Reply With Quote
  #3  
Old 24-11-2009
Member
 
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;
	  }
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Check multiple text box input"
Thread Thread Starter Forum Replies Last Post
Input text value problem NetworkeR Software Development 3 28-11-2009 11:56 AM
How to check input if it is number or not? Linoo Software Development 3 24-11-2009 04:46 PM
Setting input text values Solaris Software Development 3 23-11-2009 02:42 PM
Optical audio multiple input MAURO Portable Devices 3 25-08-2009 01:47 PM


All times are GMT +5.5. The time now is 05:59 AM.