最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

forms - Submit name value pair from javascript? - Stack Overflow

programmeradmin0浏览0评论

Can JS submit name/vale pairs through a document.testform.submit(); ? or does it have to be submitted through the html tags, for example

<INPUT TYPE="text" NAME="inputbox1" VALUE="This is such a great form!" SIZE=50><P>

Can JS submit name/vale pairs through a document.testform.submit(); ? or does it have to be submitted through the html tags, for example

<INPUT TYPE="text" NAME="inputbox1" VALUE="This is such a great form!" SIZE=50><P>
Share Improve this question asked Mar 2, 2009 at 20:48 T.T.T.T.T.T. 34.7k47 gold badges135 silver badges172 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 2

Typically you include an <input type="hidden"> in the form, and set the value you want in the event handler before it gets submitted.

<form method="post" action="thing" id="sandwich"><fieldset>
    <input type="text" name="inputbox1" value="This is such a great form!" />
    <input type="hidden" name="jsremark" />
</fieldset></form>

<script type="text/javascript">
    document.getElementById('sandwich').onsubmit= function() {
        this.elements.jsremark.value= 'Secretly it aint that great';
        return true;
    }
</script>

no, you'll have to mash it yourself into JSON using javascript

With jquery it is very simple:

$("#formid").bind("submit", function(){
 var str = $("#formid").serialize();
 $.post("url?"+str);
 return false;
}

You could set the post data of an ajax request using only JS.

It's plain simple using jQuery:

$.post(url, {"name":"value"})
发布评论

评论列表(0)

  1. 暂无评论