Swasini
Swasini

Reputation:

Form redirection using JQuery

I want to do this

<div id="myform">
<form action="http://www.google.co.in" method="post">

<input type"submit" value="google"/>

</form>
</div>

I want to change the action to someother URL , when a button is clicked. Note that i do not have any id's or name's for this form, i just have the action and method.

Any help on this is appreciated .

I tried the following,

$(document).ready(function()
{
    $("#myform form").attr("action","http://www.yahoo.com");
});

Thanks Janani

Upvotes: 1

Views: 113

Answers (2)

Pim Jager
Pim Jager

Reputation: 32129

You can identify the form using the action property:

 $(document).ready(function(){
   $("form[action='http://somesite.com']").attr("action", "http://www.example.com");
 }):

Upvotes: 2

karim79
karim79

Reputation: 342655

$(document).ready(function() { 
    $('form').attr("action","http://www.yahoo.com"); 
});

if you have more than one form, you could do something like:

$(document).ready(function() {
    //change the action of the first form 
    $('form:eq(0)').attr("action","http://www.yahoo.com"); 
});

Upvotes: 0

Related Questions