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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.