Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old October 7th, 2003, 01:23 PM
mathewvp mathewvp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 143 mathewvp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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.

Reply With Quote
  #2  
Old October 7th, 2003, 01:29 PM
CodeKadiya CodeKadiya is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Colombo,Sri Lanka
Posts: 2,313 CodeKadiya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to CodeKadiya
RE: array elements in form

Yes you can do it.

<input type=text name="username[]">
<input type=text name="email[]">

Reply With Quote
  #3  
Old October 7th, 2003, 01:49 PM
mathewvp mathewvp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 143 mathewvp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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

Reply With Quote
  #4  
Old October 7th, 2003, 04:15 PM
CodeKadiya CodeKadiya is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Colombo,Sri Lanka
Posts: 2,313 CodeKadiya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to CodeKadiya
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:
Original - php Code
  1.  
  2. for($i=0;$i<10;$i++)
  3. {
  4.  echo "<input type='text' name='username[$i]'>";
  5. }


then... you can call each box by username[2]...username[5]

Reply With Quote
  #5  
Old October 7th, 2003, 04:21 PM
mathewvp mathewvp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 143 mathewvp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: array elements in form

Still doesn't work.Gives javascript error

Reply With Quote
  #6  
Old October 7th, 2003, 04:24 PM
CodeKadiya CodeKadiya is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Colombo,Sri Lanka
Posts: 2,313 CodeKadiya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to CodeKadiya
RE: array elements in form

Look for the HTML file this page in run time... what are the textbox names for text fields...?

Reply With Quote
  #7  
Old October 7th, 2003, 04:31 PM
mathewvp mathewvp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 143 mathewvp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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>

Reply With Quote
  #8  
Old October 7th, 2003, 05:44 PM
CodeKadiya CodeKadiya is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Colombo,Sri Lanka
Posts: 2,313 CodeKadiya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to CodeKadiya
RE: array elements in form

We could easily do this... we were just playing around the problem...
php Code:
Original - php Code
  1.  
  2. <html>
  3. <script language="JavaScript">
  4. function check()
  5. {
  6.     for(var i=0;i<5;i++)
  7.     {
  8.        
  9.         if(document.form1.username[i].value=="")
  10.         {
  11.             alert("Enter value");
  12.             return;
  13.         }
  14.    
  15.     }
  16.     document.form1.submit();
  17. }
  18. </script>
  19.  
  20. <body>
  21. <form name="form1" method="post" action="users.php">
  22. <?
  23. for($i=0;$i<5;$i++)
  24.  echo "<input type=text name='username'><br>";
  25. ?>
  26. <input type="button" value="submit" onClick="check()">
  27. </form>
  28. </body>
  29. </html>
  30.  

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

Reply With Quote
  #9  
Old October 8th, 2003, 09:19 AM
mathewvp mathewvp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 143 mathewvp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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?

Reply With Quote
  #10  
Old October 8th, 2003, 10:18 AM
mathewvp mathewvp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 143 mathewvp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > array elements in form


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |