Form post submit onclick

Discussion in 'HTML & Website Design' started by hasen, Aug 24, 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 ?

    Thanks
     
    hasen, Aug 24, 2009 IP
  2. tobydawson13

    tobydawson13 Active Member

    Messages:
    645
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #2
    To do this you would need to use Javascript.
    Have a look in the Javascript forum.
     
    tobydawson13, Aug 24, 2009 IP
  3. hasen

    hasen Peon

    Messages:
    994
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I've already searched the forum and google to no avail. I can't really post this in the javascript forum as well or I'll probably get an infraction.
     
    hasen, Aug 24, 2009 IP
  4. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If all you had was this
    <button onclick="refer to your script">Submit</button>
    how would it know whether to send a 1 or a 0?

    You want to remove the text input and only have a button? Since you're doing two things (picking a value and then sending) don't you need either two form controls or at least two actions?

    But <button> elements can handle all sorts of scripting (and in your script it could set whether it was a post or a get). A <button> is allowed to replace a <input type="submit">. The problem with <button>s is when you have more than one of them, IE gets stupid and then you have to JS your way around that, but just one button on a page would be safe.

    Uh, IE also sticks a black border around buttons sometimes, I forget when cause I don't use buttons, but that's easily googleble since it's a common issue. So is the multi-button IE issue.

    Actually you can put onclick on any element. You can have a dropdown (select) who, upon onkeyup or whatever, the script is executed. The drop down could offer your two options. But I don't see how you can select or input a value with a button alone.
     
    Stomme poes, Aug 24, 2009 IP
  5. bluebenz

    bluebenz Well-Known Member

    Messages:
    876
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    138
    #5
    I am not sure about the question,
    if you want just have a a submit button and no other input appear on the screen,
    you can use :

    
    <input type="hidden" name="binset" value="1"
    
    Code (markup):
    the value can be set by script.
     
    bluebenz, Aug 24, 2009 IP
  6. TechnoGeek

    TechnoGeek Peon

    Messages:
    258
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If you want to enter either one or zero, you cannot do that using a single button. A button can only transmit one message: "the button is clicked". To transmit a one OR a zero, you need two buttons. Furthermore, if you want to dispose of the input box, you will need some JavaScript, as was already said.
     
    TechnoGeek, Aug 24, 2009 IP
  7. hasen

    hasen Peon

    Messages:
    994
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I realise I need JavaScript but how do I make it send a post value. 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.
     
    hasen, Aug 25, 2009 IP
  8. TechnoGeek

    TechnoGeek Peon

    Messages:
    258
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I don't know what you mean by a "post value". You can modify any form field in your JS script. You can assign to a field the value you want and then submit the form using "form.submit()". But then again, how would your script know if the value to assign is 1 or 0?
     
    TechnoGeek, Sep 2, 2009 IP
  9. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #9
    by POST value, it means not a GET. GET calls a file from the server who gives it as a url. POST sends or replaces a file on the server, and unlike GET doesn't have a 255 character limit (or whatever GET's limit is) and also can be more secure (you can seee everything sent in a GET request). Unless it's a search form, a form should send all information from a user via POST. And unless you want to break the user's Back button, you can do something like POST-REDIRECT-GET where after a POST is sent, a GET request is sent back to the browser, so it can go back without getting the Page Expired in IE or the Do You Want To ReSend? (which will rePOST if you say yes) in Firefox.

    If PUT was supported you could just append a file or add without replacing it : (
     
    Stomme poes, Sep 3, 2009 IP