Hi, I am extremely new to Javascript and have stumbled along a validation problem. My form is below:
<form name=“validate” action=“<?php echo $pfile;?>” onsubmit=“return Validate()” method=“post”>
<input type=“hidden” name=“patientid” id=“drugnames” value=“<?php echo $patientid;?>” />
$currentdrug = $_SESSION['prescribed'];
$sql = 'SELECT * FROM `Drug` ';
$result = mysql_query($sql);
if (mysql_num_rows($result) == 0)
echo " -- No patients found -- ";
else {
echo "<select name=\\"drugid\\">/n";
echo "<option value=\\"\\"> </option>\
";
while ($r = mysql_fetch_array($result, MYSQL_ASSOC))
echo "<option value=\\"" . $r['ref'] . "\\">" . $r['ref'] . " : " . $r['name'] . " " . $r['dose'] . "</option>\
";
echo "</select>\
";
}
?>
So basically the php script runs through every drug id and prints out the ref number, name and dose in a option value form. The variable $currentdrug produces a number. This is where my problem lies. I have created a JS function like so:
<script>
function Validate() {
valid = true;
var previous = document.getElementById('currentdrug').value;
if ( document.validate.drugid.selectedIndex == 1 && document.validate.previous.value == 5 )
{
alert ( "Big Drop" );
valid = false;
}
return true;
}
</script>
I am trying to say, if the selected index is 1 and the current drug is equal to 5, an alert is produced, but having no success with this function. any idea on how to amend this? Thanks in advance!