Jump to content
Sign in to follow this  
BOS

2 questions: Checkbox save to DB and select information

Recommended Posts

The second question has been solved, and now I have a problem with the enable and disable checkboxes, maybe someone can guide me to the right direction, thanks in advance :-)I have 4 webform checkboxes for 2 questions and I want it to select in one of those checkbox not both for each questions. I try this, but it's not working, can someone give me a better way to enable and disable in one of the checkbox, thankyouif (i==0) {window.document.getElementById("IptChkQues1A").checked = true;window.document.getElementById("ptChkQues1B").checked = false;window.document.getElementById("ptChkQues2A").checked = false;window.document.getElementById("ptChkQues2B").checked = false;}else if (i ==1){window.document.getElementById("IptChkQues1A").checked = false;window.document.getElementById("ptChkQues1B").checked = true;window.document.getElementById("ptChkQues2A").checked = false;window.document.getElementById("ptChkQues2B").checked = false;}else if (i ==2){window.document.getElementById("IptChkQues1A").checked = false;window.document.getElementById("ptChkQues1B").checked = false;window.document.getElementById("ptChkQues2A").checked = true;window.document.getElementById("ptChkQues2B").checked = false;}else if (i ==3){window.document.getElementById("IptChkQues1A").checked = false;window.document.getElementById("ptChkQues1B").checked = false;window.document.getElementById("ptChkQues2A").checked = false;window.document.getElementById("ptChkQues2B").checked = true;}}

Share this post


Link to post
Share on other sites
Can someone help me with this, thanks
I don't know what you're trying to do (where do the "i"s come from?), but this would be a more efficient (or, at least, easier to read) way to do what you've done:
document.getElementById("IptChkQues1A").checked = false;document.getElementById("ptChkQues1B").checked = false;document.getElementById("ptChkQues2A").checked = false;document.getElementById("ptChkQues2B").checked = false;if (i==0){	document.getElementById("IptChkQues1A").checked = true;}else if (i ==1){	document.getElementById("ptChkQues1B").checked = true;}else if (i ==2){	document.getElementById("ptChkQues2A").checked = true;}else if (i ==3){	document.getElementById("ptChkQues2B").checked = true;}

Also, I noticed that three of the checkboxes are named "ptChkQues.." but the first one is named "IptChkQues..". Is that by design?

Share this post


Link to post
Share on other sites
I don't know what you're trying to do (where do the "i"s come from?), but this would be a more efficient (or, at least, easier to read) way to do what you've done:
document.getElementById("IptChkQues1A").checked = false;document.getElementById("ptChkQues1B").checked = false;document.getElementById("ptChkQues2A").checked = false;document.getElementById("ptChkQues2B").checked = false;if (i==0){	document.getElementById("IptChkQues1A").checked = true;}else if (i ==1){	document.getElementById("ptChkQues1B").checked = true;}else if (i ==2){	document.getElementById("ptChkQues2A").checked = true;}else if (i ==3){	document.getElementById("ptChkQues2B").checked = true;}

Also, I noticed that three of the checkboxes are named "ptChkQues.." but the first one is named "IptChkQues..". Is that by design?

Thanks Jesh for replying, I'm trying to set enable and disable the checkbox, I have 4 checkboxes for 2 questions yes and no, the question 1 can only check either yes or no, not both checked at the same time, and also the same for the question #2, about the "i", it sets it as a variable, so do you have any suggestion of how to implement it, and some code examples, thanks...And the about the checkbox id, it is Id="ptChkQues" not "IptChkQues..". thanks for catching :-)

Share this post


Link to post
Share on other sites

If you are open to changing your design, I might recommend using radiobuttons rather than checkboxes. You can set up radiobutton groups so that only one item in the group can be selected at a time. Check out this page of the HTML tutorial: http://www.w3schools.com/html/html_forms.asp

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...