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?
brucegustPHP DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
This is a bit hacky
<script type='text/javascript'>
function none_Empty(elem, helperMsg){
	if(elem.value.length == 0||document.getElementById("req4").value==""){
if(document.getElementById("req4").value==""){helperMsg+="\nPlease fill out the URL"}
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
</script>

Open in new window

You would be better to just call the function (do not pass anything) and then just check whatever required fields are filled in.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.