I want to stop the Submit function when a form field has not been entered. However, the problem is that the form field is created by PHP code.
This is what I have
<connect to database code here>
while ($row = mysql_fetch_array($result))
{
$vard - $row['vard'];
$opt .= "<option value=\"$vard\">$vard</option>";
}
This gets all the possible values and puts them into the option box
<option selected>choose</option>
<? echo "$opt"; ?>
This makes the selected option in the box equal to "choose"
So if I write a JavaScript:
<SCRIPT LANGUAGE="JavaScript">
function dutch(form)
{
if (form1.box.value = "choose"){
alert('You must choose!');
return false
}
}
shouldn't that stop the submit?
This is the <form> code:
<form method="post" action=something.php name="form1" onSubmit=dutch(this)>
Does any of this make sense? Why doesn't it work - I have tried many things such as:
<form method="post" action=something.php name="form1" <? If ($vard = "choose") echo 'onSubmit=dutch(this)' ?> > etc.