Javascript Alert Box

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jan 2008
Posts: 16
Reputation: BillyMako is an unknown quantity at this point 
Solved Threads: 0
BillyMako BillyMako is offline Offline
Newbie Poster

Javascript Alert Box

 
0
  #1
Aug 20th, 2008
Hi,
I have an Alert box which pops up when a customer enters in "po box" in IE7 it doesn't let the user continue after entering "po box" in the field but in Firefox after Alerting it still lets the customer continue.

How can i make it so that on all browsers the customer cannot continue unless they remove "po box" from the field???

Javascript:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function validate() {
  2. var doc = document.create_account;
  3. var valstreet_address = new RegExp("[pP]{1}[.]*[oO]{1}[.]*[ ]*[bB]{1}[oO]{1}[xX]{1}");
  4.  
  5. if (doc.street_address.value.match(valstreet_address) != null) {
  6. alert("No P O Box Allowed in Delivery Address.");
  7. doc.street_address.focus();
  8. }
  9.  
  10. }


JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?PHP echo"<input type=text name=street_address onblur=\"validate();\" value='$street_address'>"; ?>

PROBLEM 2:

How can i get my drop down menu to populate once the user has enter a 3 digit number in postcode which starts with an 8 only?
At the moment it populates the drop down after the 4th number is enetered but if it's a 3 digit postcode starting with 8, the user needs to manualy click the Load Suburbs button.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?php echo "<input name='postcode' type=text onkeyup=\"if(this.value.length>3)reload(this.form);else return false;\" value=$postcode>"; ?>
  2.  
  3. I want it to also reload only if a 3 digit number is entered which begins with 8.
Last edited by BillyMako; Aug 20th, 2008 at 9:44 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 16
Reputation: BillyMako is an unknown quantity at this point 
Solved Threads: 0
BillyMako BillyMako is offline Offline
Newbie Poster

Re: Javascript Alert Box

 
0
  #2
Aug 20th, 2008
Problem 2 solved:

onkeyup=\"if(((this.value.charAt(0) == 8)&&(this.value.length > 2))||(this.value.length > 3))reload(this.form);else return false;\"
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Javascript Alert Box

 
0
  #3
Aug 21st, 2008
Just edit this code to match your php code.


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2.  
  3. <html>
  4.  
  5. <head>
  6.  
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  1. <style type="text/css">
  2. <!--
  3. form { margin: 2px 0 2px 0; padding: 0; }
  4. input, select { margin-top: 2px; padding: 2px; }
  5. -->
  6. </style>

  1. <script type="text/javascript">
  2. <!-- BEGIN HIDING
  3. /* This would go for the validation of 3Digits entry and it should also start on with number 8. */
  4. var post = /^[8]{1}?\d{2}$/;
  5.  
  6. /* This wil filter any combination regarding about this p.o. box blocking */
  7.  
  8. var pobox = /[pP]{1}?(\w)|(\.)[oO]{1}?(\w)|(\.)[Bb]{1}[0o]{1}[Xx]{1}/;
  9.  
  10. /* This goes for Solution1, just reEdit this for you php code. */
  11. function validate(street_address)
  12. {
  13. if ( pobox.exec(street_address) ) {
  14. alert('No P O Box Allowed in Delivery Address.');
  15. myform.street_address.focus(); return false; }
  16. else { alert('\nYour message goes here!'); }
  17. }
  18.  
  19. /* This will go with Solution2, just reconfigure this 1 to match your php code*/
  20. function pcode(pn)
  21. { if ( post.test(pn) )
  22. {
  23. var val = myform.pn.value;
  24. var sel = document.getElementsByTagName('select')[0];
  25. var newOpt = document.createElement('option');
  26. var opttxt = document.createTextNode(val);
  27. newOpt.appendChild(opttxt);
  28. sel.appendChild(newOpt);
  29. newOpt.setAttribute('value', val); window.location.reload();
  30. }
  31. else { alert('\nInvalid Entry!\nPlease Try Again.'); }
  32. } /* That does it for now and i hope this 1 helps you... Enjoy coding! */
  33. // DONE HIDING -->
  34. </script>

  1. </head>
  2. <body>
  3. <form onsubmit="return false" name="myform">
  4. City Address: <br />
  5. <input type="text" name="street_address" onchange="validate(this.form.street_address.value);" size="20" />
  6. <select name="list">
  7. <option value="">PostCode</option>
  8. </select>
  9. <br />
  10.  
  11. PostCode:<br />
  12.  
  13. <input type="text" name="pn" onchange="pcode(this.form.pn.value)" size="10" />
  14. </form>
  15. </body>
  16. </html>
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC