943,875 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 663
  • PHP RSS
Aug 12th, 2008
0

Need to work in echo in PHP

Expand Post »
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.

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

PHP Syntax (Toggle Plain Text)
  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?????
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
BillyMako is offline Offline
16 posts
since Jan 2008
Aug 12th, 2008
0

Re: Need to work in echo in PHP

I just fixed your double-quotes and it worked
PHP Syntax (Toggle Plain Text)
  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 ...
PHP Syntax (Toggle Plain Text)
  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 ...
PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 30
Solved Threads: 36
Posting Whiz
langsor is offline Offline
389 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 PHP Forum Timeline: insert into database problem
Next Thread in PHP Forum Timeline: search form with alphabetical order





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


Follow us on Twitter


© 2011 DaniWeb® LLC