Form post submit onclick

Discussion in 'JavaScript' started by hasen, Aug 30, 2009.

  1. #1
    I want to simply submit a value via POST (not GET) by clicking a button in a form. At the moment I type in a value of either 0 or 1 into a text box and then click submit. I'd rather this was achieved in one button click. My code at present looks like this:

    
    
    <form method='post'>
    <input type='text' name='binset' site='1'>
    <input type='submit' value='Submit'>
    </form>
    
    Code (markup):
    How can I submit this with one button click using ONCLICK ? I've already managed to do it using get with single click buttons but get is gonna cause further problems. Maybe I need to post about it on the JavaScript forum. I think I need the onclick to trigger a JavaScript function which sends a post value and also reloads the page.

    Thanks
     
    hasen, Aug 30, 2009 IP
  2. prasanthmj

    prasanthmj Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    45
    #2
    something like this?
    
    <form method='post' action='script.php' name='linkform'>
    <input type='hidden' name='binset'>
    <input type='button' onclick='javascript: document.linkform.binset=2; document.linkform.submit();' value='Submit'>
    </form>
    
    HTML:
     
    prasanthmj, Aug 31, 2009 IP
  3. hasen

    hasen Peon

    Messages:
    994
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks. What's the javascript code for this though?
     
    hasen, Aug 31, 2009 IP