ok so, the title of this question might be a little confusing, and i will try to explain it to you: i have a php file with an array containing multiple form fields like this:
$var = array(0 => '<input type=....>', 1=> '<input type=....>');
and i created a while loop to loop through the array to show them in a table, something like this:
echo '<table>';
while($row = mysql_fetch_array($result)){
$num = $row['fieldId'];
$field = $num.' '.$row['field'];
echo '<tr><td>'.$field.'</td>';
echo '<td>'.$var[$q].'</td></tr>';
echo '<tr><td> </td></tr>';
$q++;
}; echo '</table>';
i included this php file in a html file so i can get a table with two columns, the first one with $field from the database and the second with $var[$q] which is some input field taken from the $var array.
Believe it or not that actually works, now the problem is that inside that $var array i have a <select>
field with multiple options, i want to validate that field with some javascript, but for some reason i can't get the values assigned in <option value="SOMEVALUE">
. i don't know why but i can't, one thing i found weird is that in that $var array i have some radio buttons which i CAN validate with javascript.
more info: the html file that includes the php file has this:
<html>....
<form name="mainForm">
<?php
include 'myPhpFile.php';
?>
<input type="button" name="btnNext" onclick="functionToValidate();">
</form>
...</html>
so basically when i include my php file it creates a table and adds fields to it filling them with data from a mysql database and some input fields using the $var array shown above
all that works, but the problem is when i click the next button it calls a javascript function to validate the fields, everything works until it gets to the <select>
input,
i can validate radio buttons, text fields and textareas but i can't validate those <select>
this is the javascript function i am using:
function myFunctionNameHere(){
if(!document.mainForm.p1_1[0].checked && !document.mainForm.p1_1[1].checked)
alert("1 - some warning here");
else if(!document.mainForm.p1_2[0].checked && !document.mainForm.p1_2[1].checked)
alert("2 - some warning here");
else if(!document.mainForm.p1_3[0].checked && !document.mainForm.p1_3[1].checked)
alert("3 - some warning here");
else if(!document.mainForm.p1_4[0].checked && !document.mainForm.p1_4[1].checked)
alert("4 - some warning here");
else if(!document.mainForm.p1_5[0].checked && !document.mainForm.p1_5[1].checked)
alert("5 - some warning here");
else if(!document.mainForm.p1_6[0].checked && !document.mainForm.p1_6[1].checked)
alert("6 - some warning here");
else if(document.mainForm.p1_7.value == "")
alert("7 - some warning here");
// this condition does not work:
else if(document.mainForm.p1_8.selectedIndex == 0)
alert("8 - some warning here);
// can't get the selectd field from the html select field
else
window.location = "OTHERPAGE.html";
}
that's pretty much what the function does, all conditions work except for that one i put the comments on. (i'm still learning so don't laugh at my code... please.)
Sorry i actually got this solved, there were some errors in the html code from my php array. Now it actually works. Thanks.