cedric Posted June 5, 2009 Share Posted June 5, 2009 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 comment Share on other sites More sharing options...
smerny Posted June 5, 2009 Share Posted June 5, 2009 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)}} Link to comment Share on other sites More sharing options...
cedric Posted June 5, 2009 Author Share Posted June 5, 2009 i'm trying to get it to work but I keep getting erors? Link to comment Share on other sites More sharing options...
inktherapy Posted June 8, 2009 Share Posted June 8, 2009 What do you mean by 1 box? an alert box? Link to comment Share on other sites More sharing options...
cedric Posted June 8, 2009 Author Share Posted June 8, 2009 yes in one popup alert box instead of every message beïng a different popup Link to comment Share on other sites More sharing options...
justsomeguy Posted June 8, 2009 Share Posted June 8, 2009 Check the variable name spelling, the alert text variable is spelled one way three times, and another way three times. Link to comment Share on other sites More sharing options...
cedric Posted June 9, 2009 Author Share Posted June 9, 2009 will do Link to comment Share on other sites More sharing options...
justsomeguy Posted June 9, 2009 Share Posted June 9, 2009 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);} Link to comment Share on other sites More sharing options...
inktherapy Posted June 10, 2009 Share Posted June 10, 2009 I agree some statements are not properly open or closed. Link to comment Share on other sites More sharing options...
cedric Posted June 10, 2009 Author Share Posted June 10, 2009 works perfect thanks alot. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.