tags:

views:

38

answers:

2

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

A: 
$(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"); 
});
karim79
thanks this works!$('form:eq(0)').attr("action","http://www.yahoo.com");
Swasini
I have one more Question. I have a url , say for eg https://www.dev23.com /.Here i need to get .dev23.com from an xml , this will dynamically change for different site. How do i do this?Thanks in advance.
Swasini
url is : http://www.dev23.com
Swasini
+2  A: 

You can identify the form using the action property:

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