Need to work in echo in PHP

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

Need to work in echo in PHP

 
0
  #1
Aug 12th, 2008
I have this script working and now i just need the alert to pop up when the field is in PHP.
But when i put it in echo"" the onBlur event wont work.

  1. function validate() {
  2. var valStreet = new RegExp("[pP]{1}[.]*[oO]{1}[.]*[ ]*[bB]{1}[oO]{1}[xX]{1}"); //Anything with "PO BOX" alerted
  3.  
  4. if (form.Street.value.match(valStreet) != null) {
  5. alert("No P O Box Allowed in Shipping Address.");
  6. }
  7. }
  8. </script>
  9. </head>
  10. <body><form name="test">
  11. Street: <input type="text" name="street" value="" onBlur="validate();"><br>
  12. <input type="button" name="test" value="test">
  13. </form>

  1. <?PHP echo"<input type='text' name='street' onBlur=\"validate();\" value=$street >"; ?>
  2.  
  3. //Something wrong with the onBlur Code!!!!

What is the correct way to get onBlur to work when in PHP?????
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 381
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 33
langsor langsor is offline Offline
Posting Whiz

Re: Need to work in echo in PHP

 
0
  #2
Aug 12th, 2008
I just fixed your double-quotes and it worked
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function validate() {
  5. var valStreet = new RegExp("[pP]{1}[.]*[oO]{1}[.]*[ ]*[bB]{1}[oO]{1}[xX]{1}"); //Anything with "PO BOX" alerted
  6.  
  7. if (form.Street.value.match(valStreet) != null) {
  8. alert("No P O Box Allowed in Shipping Address.");
  9. }
  10. }
  11. </script>
  12. </head>
  13. <body>
  14. <?php
  15. $street = 'ez';
  16. ?>
  17. <form name="test">
  18. Street:
  19. <?php print "<input type=\"text\" name=\"street\" onBlur=\"validate();\" value=\"$street\" >"; ?>
  20.  
  21. <!--<input type="text" name="street" value="" onBlur="validate();">-->
  22. <br>
  23. <input type="button" name="test" value="test">
  24. </form>
  25. </body>
  26. </html>

Did you know that with regular expressions you can do a case-insensitive modifier and not have to do dB type stuff.
Something like this ...
  1. .match( /p.*?o.*?b.*?o.*?x.*/i );
...should work, but RegEx is always tricky and I didn't actually test the above
For that matter, you could probably get away with just this ...
  1. .match( /.*?box/i ); // pobox, po box, post office box, mail box, postal box (all in upper and/or lower case)

Enjoy
Last edited by langsor; Aug 12th, 2008 at 2:25 am.
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC