|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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;
}
|
|
#3
|
|||
|
|||
|
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. |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > Arrays and Form Validation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|