Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

How to use Javascript to validate two fields before form submission?

Here's my code:

<table cellspacing="0" cellpadding="0" style="margin:auto;"><form action="link_insert_execute.php" method="Post">
<tr>
<td>
Link Type&nbsp;
</td>
<td class="standard">
<script type='text/javascript'>
function none_Empty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
</script>
<select name="link_type" id='req3'/>
<option></option>
<option>facebook</option>
<option>google plus</option>
<option>instagram</option>
<option>itunes</option>
<option>linked in</option>
<option>myspace</option>
<option>store</option>
<option>twitter</option>
<option>webpage</option>
<option>youtube</option>
<option>______________________________</option>
</select>			
</td>
</tr>
<tr>
<td>
URL&nbsp;
</td>
<td>
<input type="text" size="35" name="url" id='req4'/>
</td>
</tr>
<tr>
<td align="center" colspan="2">&nbsp;<BR>
<input type="hidden" name="registration_id" value="<?php echo $novie_id; ?>">
<input type="submit" value="submit" onclick=" return none_Empty(document.getElementById('req3'), 'Please submit an icon type in the logo field.')" value='Check Field' />
</td>
</tr>
</table>

Open in new window


It works great, as far as validating the social icon list, but I need to validate the URL field as well. Can I use the same kind of scripting that I have in place to validate two fields and not just the one?
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial