|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
array elements in form
hi,
I have a form with 10 fields for usernames and 10 fields for emailids.This is for sending bulk mails.Now I want to check if the user has put any usernames,and if he has then check for the emailid's validity.The no: of entries is dependant on the user ie if he wishes to send mail to only 4 four users,he need to enter only four names and emailids. Now is it possible to use array names for textfields so that the validification can be done easily using for loop. |
|
#2
|
|||
|
|||
|
RE: array elements in form
Yes you can do it.
<input type=text name="username[]"> <input type=text name="email[]"> |
|
#3
|
|||
|
|||
|
RE: array elements in form
ok then how do I access it within javascript for validation?
document.form1.username[i].value gives error(value of i has been set) Thanks |
|
#4
|
|||||
|
|||||
|
RE: array elements in form
you may do something like this... just got this idea now.
when you first display the textboxes, do it like this... php Code:
then... you can call each box by username[2]...username[5] |
|
#5
|
|||
|
|||
|
RE: array elements in form
Still doesn't work.Gives javascript error
|
|
#6
|
|||
|
|||
|
RE: array elements in form
Look for the HTML file this page in run time... what are the textbox names for text fields...?
|
|
#7
|
|||
|
|||
|
RE: array elements in form
Ok heres the quick code
<html> <script language="JavaScript"> function check() { for(var i=0;i<5;i++) { if(document.form1.username[i].value=="") { alert("Enter value"); return; } } document.form1.submit(); } </script> <body> <form name="form1" method="post" action="users.php"> <input type="text" name="username[0]"><br> <input type="text" name="username[1]"><br> <input type="text" name="username[2]"><br> <input type="text" name="username[3]"><br> <input type="text" name="username[4]"><br> <input type="button" value="submit" onClick="check()"> </body> </html> |
|
#8
|
|||||
|
|||||
|
RE: array elements in form
We could easily do this... we were just playing around the problem...
php Code:
just give names for 5 textfields as usual. Ex : name="email" You can call each box in javascrip Ex : document.form1.email[0].value document.form1.email[2].value |
|
#9
|
|||
|
|||
|
RE: array elements in form
Ok Codekadiya,you solved the javascript part.Now How do I get the values after the form gets submitted in the php script?
|
|
#10
|
|||
|
|||
|
RE: array elements in form
I found out the solution.It was so simple
Code:
<html>
<script>
function check()
{
for(var i=1;i<6;i++)
{
if(document.getElementById('username'+i).value=="")
{
alert("Enter a value");
document.getElementById('username'+i).focus();
return;
}
}
}
</script>
<body>
<form name="form1">
<input type="text" name="username1"><br>
<input type="text" name="username2"><br>
<input type="text" name="username3"><br>
<input type="text" name="username4"><br>
<input type="text" name="username5"><br>
<input type="button" value="click Me" onClick="check()">
</form>
</body>
</html>
Thanks Codekadiya for your help |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > array elements in form |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|