SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    click one checkbox will submit only one checkbox value (not the whole form)

    My JSP web page has many checkboxes.
    What is web page source code look like when clicking one checkbox will submit only one checkbox value (not the whole form) immediately?
    i.e. toggling one checkbox will send the info that only that checkbox is toggled.
    This does not work because clicking one checkbox will send the whole page
    <form name="myform" method="post">
    <input type="checkbox" name="choice" value="1" onclick="submit();">
    <input type="checkbox" name="choice" value="2" onclick="submit();">
    <input type="checkbox" name="choice" value="3" onclick="submit();">
    ...

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,871
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    If each checkbox is a separate form then give each their own separate form tag.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    If each checkbox is a separate form then give each their own separate form tag.
    Is it possible to have only one form?

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    It is possible to have only one form if you want to submit to only one page.

    You can screw about with that using javascript, but then it will fail for your visitors around 10&#37; of the time.

    The better alternative is to make the server-side smarter, so that it directs the form submission where it needs to go, or to use multiple forms on the page.
    When you us multiple forms (with multiple submit buttons) you can then use javascript to hide the submit buttons and make the page behave as you intend.

    The danger of submitting when a checkbox is clicked is that it conflicts with how people know web forms work on the 1000+ other web forms they have recently used.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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