Jump to content

Recommended Posts

Hi can someone tell me how to put these two alerts (if nessesary) in 1 box.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>blijf op de hoogte</title><link rel="stylesheet" type="text/css" href="css/form.css" media="all"><script type="text/javascript">function wissen() { 	document.getElementById('suggesties').innerHTML="";}function validate() {	var tekst=document.getElementById('email').value;		if (!tekst) { 			tekst=document.getElementById('fax').value};		if (!tekst) { 			alert ('gelieve iets in te vullen');}	var drop=document.getElementById('subjects').value;		if (drop==0) {			alert('gelieve een keuze te maken')}}function validate_1() {	var tekst=document.getElementById('email').value;	if (!tekst) { 		tekst=document.getElementById('fax').value};	if (!tekst) { 		alert ('gelieve iets in te vullen'); return false;}	else {	var drop=document.getElementById('subjects').value;	if (drop==0) {		alert('gelieve een keuze te maken')}}}function validate_2(){}</script></head><body><fieldset><legend>Onderwerpen waarover u meer info wenst</legend>	<label for="email">email naar</label>	<input type="text" name="email" id="email" /><br />		<label for="fax">faxen naar</label>	<input type="text" name="fax" id="fax" /><br />		<label for="subjects">onderwerpen</label>	<select id="subjects" name="cbxSubject">		<option value="0">«uw keuze»</option>		<option value="1">Java</option>		<option value="2">Databanken</option>		<option value="3">Multimedia</option>	</select><br />		<label for="subjects">suggesties</label>	<textarea id="suggesties" rows="8" cols="25" onfocus="wissen()">	«uw suggesties»</textarea>	<input class="knop" type="submit" id="ok" value="OK" onclick="validate_1()"/>	</fieldset></body></html>

Link to post
Share on other sites

try

function validate_1() {var tekst=document.getElementById('email').value;if (!tekst) tekst=document.getElementById('fax').value};var alarttxt="gelieve iets in te vullen"; return false;}else {var drop=document.getElementById('subjects').value;if (drop==0) {if (alerttxt){alarttxt += " and ";}alarttxt += "gelieve een keuze te maken")}}if (alerttxt) {alert (alarttxt)}}

Edited by smerny
Link to post
Share on other sites

Actually the code that smerny posted has more problems than just that, that habit of putting closing brackets at the end of a line makes for some real confusing code. Take a look at this version:

function validate() {  var alert_text = "";  var tekst=document.getElementById('email').value;  if (!tekst)  {	tekst=document.getElementById('fax').value;  }  if (!tekst)  {	alert_text += 'gelieve iets in te vullen\n';  }  var drop=document.getElementById('subjects').value;  if (drop==0)  {	alert_text += 'gelieve een keuze te maken\n';  }    if (alert_text != "")	alert(alert_text);}

Edited by justsomeguy
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...