deafdigit
12-14-2011, 03:13 PM
Hi everybody,
I have a php file with an almost-standard html form. The not-so-standard part is that the name-attributes of the form elements are dynamically generated as such:
<? for($i=0; $i<5; $i++) { ?>
<input type="text" name="field_<? echo $i; ?>" />
<? } ?>
Now I want to do some javascript validation on the fields, but I'm having a bit of trouble accessing the values of the fields. My current code is as follows:
var i = 0;
var num = <? echo $step1_sag_faktura_num; ?>;
for (i=0; i<num; i++){
window['file_' + i] = document.forms["nyisagform_step2"]["sag_fak_file_" + i].value;
}
But this doesn't seem to work. It gives no error message. It just validates true.
Can somebody tell me a way to do this? I'm no good at javascript and the code above is pieced together by bit I found on the internet.
Thanks in advance,
deafdigit
I have a php file with an almost-standard html form. The not-so-standard part is that the name-attributes of the form elements are dynamically generated as such:
<? for($i=0; $i<5; $i++) { ?>
<input type="text" name="field_<? echo $i; ?>" />
<? } ?>
Now I want to do some javascript validation on the fields, but I'm having a bit of trouble accessing the values of the fields. My current code is as follows:
var i = 0;
var num = <? echo $step1_sag_faktura_num; ?>;
for (i=0; i<num; i++){
window['file_' + i] = document.forms["nyisagform_step2"]["sag_fak_file_" + i].value;
}
But this doesn't seem to work. It gives no error message. It just validates true.
Can somebody tell me a way to do this? I'm no good at javascript and the code above is pieced together by bit I found on the internet.
Thanks in advance,
deafdigit