Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing form method with js on firefox

I need to change the method attribute of my form with javascript (jQuery or pure).

My form has method="post", i try to change it with:

$("#submit-button").click(function(){ 
    var url = $('input[id=url]').val();
    var method = $('#method option:selected').val();
    $("#form-test").attr("action", url); 
    $("#form-test").attr("method", method);
    $("#form-test").submit();
});

This code works on Chrome and I8 but not on Firefox. The action is set correctly and also method variable contains "get" or "post" correctly. Any idea?

SOLVED: I was using an old version of jquery (copy&paste fault), i've upgraded to 1.7.1 and now it works, with the same code...

like image 443
aberti Avatar asked Dec 05 '22 18:12

aberti


2 Answers

this is my code, and it works just fine on both IE/FF/Chrome

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
function changeMethod() {
    $("#myPost").attr("method", "get");
}
</script>

<form method="post" id="myPost">
    <input type="text" name="abc" id="abc" value="Something" />

    <input type="submit" value="submit" onclick="changeMethod()" />
</form>
like image 76
Churk Avatar answered Dec 30 '22 00:12

Churk


Try this:

$(function(){
    $("#form").attr("method", "get");
});
like image 34
wanovak Avatar answered Dec 29 '22 22:12

wanovak