Jump to content

PHP and JS question


dk4210

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/248985-php-and-js-question/
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/248985-php-and-js-question/#findComment-1278697
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/248985-php-and-js-question/#findComment-1278765
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.