Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

CHECKBOX onclick submission from struts

Tsoy78Tsoy78 Posts: 24Member
Hi. I have a small question to ask:

I am using struts with the Jsp page, and I am using the struts' HTML library.

So, having the following code:



Instead of SOMETHING at the onclick attribute I have a javascript that submits the form. However, I ran into this trouble.
When the check box is not checked initially, the form gets subitted fine, the check box gets checked and everything that has to happen happens.
However, when the check box is initially checked and want to uncheck it, and on this unchecking I want the form to get submitted with the knowledge that a checkbox was cleared, THIS DOESN'T HAPPEN.
I found out that this is a common web problem - not just a JSP or struts'. I also heard that there is some way to mitigate this by using some kind form's reset() method of the Struts API, or something .. I am not clear on what it is and how to go about this. I'll greatly appreciate the help in this matter.

Comments

  • mac_doggiemac_doggie Posts: 488Member


    : Hi. I have a small question to ask:
    :
    : I am using struts with the Jsp page, and I am using the struts' HTML library.
    :
    : So, having the following code:
    :
    :
    :
    : Instead of SOMETHING at the onclick attribute I have a javascript that submits the form. However, I ran into this trouble.
    : When the check box is not checked initially, the form gets subitted fine, the check box gets checked and everything that has to happen happens.
    : However, when the check box is initially checked and want to uncheck it, and on this unchecking I want the form to get submitted with the knowledge that a checkbox was cleared, THIS DOESN'T HAPPEN.
    : I found out that this is a common web problem - not just a JSP or struts'. I also heard that there is some way to mitigate this by using some kind form's reset() method of the Struts API, or something .. I am not clear on what it is and how to go about this. I'll greatly appreciate the help in this matter.
    :

    Hi,

    I think the problem you are having is caused by the fact that if a checkbox is not checked, it is not send with the form data.

    What you can do is create a hidden field with the name the checkbox has now. In the onClick of your checkbox you should now change the value of the hidden field something like this:


    [code]
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />


    website - page






    function setCheckbox() {
    document.getElementById('theCheckbox').value=(document.getElementById('theCheckbox').value=='off')?'on':'off';
    alert(document.getElementById('theCheckbox').value);
    //document.forms['theForm'].submit();
    }














    [/code]

    if you now submit the form you will have an on or off value, and it doesn't matter anymore that the checkbox isn't checked.

    good luck, let me know if it worked.


    ;-)
    -mac-
    mailto:mac_doggie@hotmail.com
    the Netherlands...


Sign In or Register to comment.