Search code examples
javascriptmootools

Modify Form Submission string


I want to limit the values that get passed within my form. So for example:

<form action="" method="get">
    <input name="check1" type="radio" value="123" checked>
    <input name="check2" type="radio" value="456" checked>
    <input name="check3" type="radio" value="789" checked>
    <input type="submit" title="submit" id="btn_submit">
</form>

Now if I goto submit that I get something like below for the url

www.domain.com/?check1=123&check2=456&check3=789

How can I control that to send just 'check3'? So the url would be

www.domain.com/?check3=789


Solution

  • Your radio buttons should share the same name. Give them unique IDs if you need to identify them with JS.

    <form action="" method="get">
        <input name="check3" type="radio" value="123" checked>
        <input name="check3" type="radio" value="456" checked>
        <input name="check3" type="radio" value="789" checked>
        <input type="submit" title="submit" id="btn_submit">
    </form>
    

    If that's not what you want, only include the input fields in the form if you want them to be included in the submission.