www.webdeveloper.com
Results 1 to 2 of 2

Thread: Why does creating/submitting form in javascript put values in querystring?

  1. #1
    Join Date
    May 2009
    Posts
    127

    Why does creating/submitting form in javascript put values in querystring?

    I want to create and submit my form dynamically and have it submit to a page just like a normal form, but when I do this, it puts the values in the query string, not passing them as post values like normally. Why is this?

    Code:
    <script>
    
    //Create the form
    var form = document.createElement( "form" );
    
    //Set action (this ends up showing as http://localhost/getform.php?myInput=val
    form.action = "getform.php";
    
    //Set the type (I've also tried "application/x-www-form-urlencoded"
    form.enctype = "multipart/form-data";
    
    //Add to document
    document.body.appendChild( form );
    
    //Create an input, set type, and add to form
    var input = document.createElement( "input" );
    input.type = "text";
    input.name = "myInput";
    input.value = "val";
    form.appendChild( input );
    
    //Submit the form
    form.submit();
    </script>
    What am I doing wrong?

  2. #2
    Join Date
    May 2009
    Posts
    127
    Never mind, I forgot:

    form.method = "POST";

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles