1

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>

5 Answers 5

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>
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

1

With jquery it is very simple:

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

1 Comment

Trying to limit adding any libraries, but looks tempting
1

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

Comments

0

It's plain simple using jQuery:

$.post(url, {"name":"value"})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.