dk4210 Posted October 12, 2011 Share Posted October 12, 2011 Hello Guys, I am trying to get this js to work with my PHP form and I need some help.. I have the following form echo' <form id="form" name="form" method="post" action="index.php?content=listings&cid='.$cid2.'&id='. $id2 . '&contact=1" onsubmit="demo12"> <label> <span class="small">Name</span> </label> <input type="text" name="name" id="name" class="validate(required)" value="'.$_SESSION['fname'] .' '.$_SESSION['lname'] .'" /> <label> <span class="small">Email Address</span> </label> <input type="text" name="email" id="email" class="validate(required,email)" value="'.$_SESSION['email'] .'" /> <label> <span class="small">Comments</span> </label> <textarea id="conowntxtarea" class="validate(required) name="comments"></textarea><br /> <button id="demo12" type="submit">Send to Owner</button> <div class="spam_warning">Warning: Spam or Harrassment will not be tolerated!</div> <div class="spacer"></div> </form>'; And the following js code <script type="text/javascript"> $(document).ready(function() { $('#demo12').click(function() { $.growlUI('Growl Notification', 'Have a nice day!'); }); }); </script> I want to be able to submit the form and it activate the js script notification before it completes the form action url.. Could some one give me a hand with this? Thanks, Dan Quote Link to comment https://forums.phpfreaks.com/topic/248985-php-and-js-question/ Share on other sites More sharing options...
AyKay47 Posted October 12, 2011 Share Posted October 12, 2011 should trigger the function once the button with id #demo12 is clicked as your code is now.. what exactly is happening? Quote Link to comment https://forums.phpfreaks.com/topic/248985-php-and-js-question/#findComment-1278677 Share on other sites More sharing options...
dk4210 Posted October 12, 2011 Author Share Posted October 12, 2011 Hi thanks for the quick response What seems to be happening is the page basically reloads itself and when it does it never displays the notification. Quote Link to comment https://forums.phpfreaks.com/topic/248985-php-and-js-question/#findComment-1278679 Share on other sites More sharing options...
AyKay47 Posted October 12, 2011 Share Posted October 12, 2011 i see, I think that you will need your function to return false to stop the default submit execution from happening.. <script type="text/javascript"> $(document).ready(function() { $('#demo12').click(function() { $.growlUI('Growl Notification', 'Have a nice day!'); return false; }); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/248985-php-and-js-question/#findComment-1278697 Share on other sites More sharing options...
dk4210 Posted October 12, 2011 Author Share Posted October 12, 2011 How would I do that? Quote Link to comment https://forums.phpfreaks.com/topic/248985-php-and-js-question/#findComment-1278715 Share on other sites More sharing options...
markjoe Posted October 12, 2011 Share Posted October 12, 2011 you are telling it to do 2 things at once and the form submission will (I think) always win. Get rid of the click handler on the submit button. Just define the function. function growl(){ $.growlUI('Growl Notification', 'Have a nice day!'); } and then tell it to run when the form is submitted <form -snip- onsubmit="return growl();"> having the return in the onsubmit attribute allows you to return false from the function to cancel the submission if you please. Quote Link to comment https://forums.phpfreaks.com/topic/248985-php-and-js-question/#findComment-1278765 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.