Hello.

This is working for me now. thanks for the help. This is what I'm doing now:

$(document).ready(function(){
            $("#videos").submit(function(){
                        
                        $("#videos").ajaxForm(function(data){
                                //alert("Form submit succeded! Server returned 
"+data);
                                $("div#msg").html(data);
                        });
                        return false;
        
            });
        });
        
        </script>

But there seems to be a strange problem. Form gets submitted only when I hit the submit button, not if I hit Enter. (I'm using Firefox on a Macbook Pro). Why would it not work with Enter?

Thanks again,

Gaston

On Feb 7, 2007, at 9:53 AM, Klaus Hartl wrote:

Gaston Garcia schrieb:
Hello, I've been trying to submit a Form to a php file to send an email.
I've already tested the script without jquery, to make sure the php
works ok.

I haven't been able from the examples to know how to do it. This is the
last I tried:

*This is what I have in my script tag in the head:*

$(document).ready(function(){
$("input#submit").click(function(){
var params = $("[EMAIL PROTECTED]").serialize();   /*I try to get all
the input fields here into value pairs*/
$("div#msg").ajax({
type:"POST";
url:"sendmails.php";
data:params;
success:function(msg){
alert("sent ok! "+ msg);
}
});
});
});

Gaston, you are attaching the wrong event. Instead of using the click
event for the submit button, you have to use the submit event of the
form - remember that you can always submit a form without clicking but
by hitting enter. You also have to append a "return false" at the end to
stop the form from submitting...:

$(function() {
     $("#videos").submit(function() {
         var params = $('[EMAIL PROTECTED]"text"]', this).serialize();
         $.ajax({
             type:"POST",
             url:"sendmails.php",
             data: params,
             success: function(msg) {
                 alert("sent ok! "+ msg);
             }
         });
     });
});

You were also using ";" instead of "," in your options object literal
for the $.ajax function - and you were using this incorrectly as
$('#msg').ajax(...)

That should have given you a few JavaScript errors on the console. I
highly recommend using FireBug or at least the browser's JavaScript
console if you want to do some serious JavaScript developing.

If you want to update an element with the response, use the success
handler for this:

success: function(msg) {
     $('#msg').html(msg);
}

This is a great example to use the form plugin and make it totally
unobtrusive. You would first build your form in a way that it works
without JavaScript (you have to do that anyway, because in the end it
doesn't matter which type of request your GET/POST variables come from)
and as soon as this works you can just plug in some Ajax magic:

$('#videos').ajaxForm();

The form should look like

<form id="videos" action="sendmails.php" method="post">
...
</form>

for this.


Cheers, Klaus




_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to