943,546 Members | Top Members by Rank

Ad:
Aug 20th, 2008
0

Javascript Alert Box

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
BillyMako is offline Offline
16 posts
since Jan 2008
Aug 20th, 2008
0

Re: Javascript Alert Box

Problem 2 solved:

onkeyup=\"if(((this.value.charAt(0) == 8)&&(this.value.length > 2))||(this.value.length > 3))reload(this.form);else return false;\"
Reputation Points: 10
Solved Threads: 0
Newbie Poster
BillyMako is offline Offline
16 posts
since Jan 2008
Aug 21st, 2008
0

Re: Javascript Alert Box

Just edit this code to match your php code.


html Syntax (Toggle Plain Text)
  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" />

css Syntax (Toggle Plain Text)
  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>

javascript Syntax (Toggle Plain Text)
  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>

html Syntax (Toggle Plain Text)
  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>
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: popup or new window or whatever?
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Javascript is not working in IE6





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC