i have a list which contains some element.How can i put mandatory check in this list since select required is not supported by any major browser.
<th>From *</th>
<th><select name="from">
<option value="builder">Builder</option>
<option value="broker">Broker</option>
<option value="seeker">Seeker</option>
<option value="owner">Owner</option>
<option value="regular cf user">Regular CF user</option>
<option value="ams user">AMS user</option>
<option value="home needs user">Home Needs User</option>
</select>
</th>
this is my given list i want to check for mandatory field.
Once you POST the form, just check for the value, and if it is empty/missing, show an error:
if (! isset($_POST['from']) || empty($_POST['from']))
{
// Deal with the fact that a mandatory field was not provided.
}
Use javascript.
<th>From *</th>
<th><select name="from" onchange="return validate();">
<option value="">Select One</option>
<option value="builder">Builder</option>
<option value="broker">Broker</option>
<option value="seeker">Seeker</option>
<option value="owner">Owner</option>
<option value="regular cf user">Regular CF user</option>
<option value="ams user">AMS user</option>
<option value="home needs user">Home Needs User</option>
</select>
</th>
Javascript
<script type="text/javascript>
function validate()
{
var from=document.getElementsByName('from').value;
if(from==""){
alert('Please select an option');
}
return true;
}
</script>: