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 December 9th, 2004, 01:20 PM
lmayer lmayer is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: USA
Posts: 225 lmayer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Arrays and Form Validation

Morning,

I have a similar situation to the post http://codewalkers.com/forum/index.php?action=displaythread&forum=clientside&id=263&realm=default.

However my field names are very difficult since they are all in arrays.

The field name is:

<input name="rowdata[<?PHP echo $cnt; ?>][TrailerID]" type="text" value="<? echo $arrRowData[$cnt]['TrailerID']; ?>" size="10">

I want to use Javascript to check the form before it's sent to the dataabse. However I can't figure out for the life of me how to get javascript to match the name.

I took the code above and changed it but not enough I guess:

<!-- form validation -->
<SCRIPT LANGUAGE="JavaScript">
function check()
{

for(var i=1;i<6;i++)
{

if(document.form1('rowdata'+i+'TrailerID').value== "")
{
alert("Enter a value");
document.form1('rowdata'+i+'TrailerID').focus();
return;
}
}
}

// End -->
</script>

Any help would be appreciated.

Thanks

Laura

Reply With Quote
  #2  
Old December 9th, 2004, 02:09 PM
nawlej nawlej is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Dallas, Tx. USA
Posts: 2,008 nawlej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 7 m 51 sec
Reputation Power: 4
RE: Arrays and Form Validation

Wouldnt it be something like this, because your denoting an array element, and not a string:

Code:
if(document.form1(rowdata[i]['TrailerID']).value=="")
{
alert("Enter a value");
document.form1(rowdata[i]['TrailerID']).focus();
return;
}

Reply With Quote
  #3  
Old December 9th, 2004, 02:21 PM
lmayer lmayer is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: USA
Posts: 225 lmayer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Arrays and Form Validation

I did find the answer. It was in the manual most of the way down.


"For all of you having problems when using php arrays in an HTML form input field name, and wanting to validate the form using javascript for example, it is much easier to specify an id for the field as well, and use this id for validation.

Example:

<input type="text" id="lastname" name="fields[lastname]">

then in the javascript check:

if(formname.lastname.value == "") {
alert("please enter a lastname!");
}
"

Now my only problem is because it's in an array it only checks the first one. Not all the others.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > Arrays and Form Validation


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


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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT