Jump to content

Checkbox Onchange Unchecks Different Checkbox


Go to solution Solved by geoffdude,

Recommended Posts

Hi,

 

I have a form with 3 checkboxes. A visitor can select any checkbox to get the products they want: newspaper or magazine, both, or just one. --- The visitor can also select to get the e-newsletter, but only if the newspaper checkbox is selected. Else the e-newsletter checkbox is disabled (which is a rule set configured in the form that works fine).

 

What I need.. is a function for if someone chooses both "newspaper" and "e-newsletter" checkboxes then decides that they don't want "newspaper" and deselect it (which leaves e-newsletter still checked). I need an onchange function that unchecks the "e-newsletter" checkbox at the exact same time newspaper is unchecked.

 

Note - The exisitng rule makes the checkbox disabled and enabled, but it doesn't uncheck it.

 

 

SAMPLE OF FORM:

 

1)    [  ] Get this free newspaper       /--> OC_news_print = id

1b)  [  ] Get the e-newsletter too      /--> OC_news_eletter = id

 

2)    [  ] Get this different magazine

 

 

 

-- SOMETHING LIKE CODE BELOW IS NEEDED - MINE / IT DOESN'T WORK ---

 

<! -- vars NEEDED AT ALL ?
var ocPrint = document.getElementById("InsertRecordOC_news_print");
var ocEnews = document.getElementById("InsertRecordOC_news_eletter");

-->


 function ocProductsCheck() {
 if (document.getElementById('InsertRecordOC_news_print').checked.length<1) {

document.getElementById("InsertRecordOC_news_eletter").checked=false;
}
else {
      if (document.getElementById('InsertRecordOC_news_print').checked.length>0) {

document.getElementById("InsertRecordOC_news_eletter").checked=false;

    }

 }
 document.getElementById("InsertRecordOC_news_print").onchange=ocProductsCheck;


Thanks - Geoff

Link to post
Share on other sites
Hi Geoff,

 

You can use following code in the footer field: 

 

<script>

function ocProductsCheck() {

if (document.getElementById('InsertRecordOC_news_print').checked.==false) 

   {

    document.getElementById("InsertRecordOC_news_eletter").checked=false;

   }

}

document.getElementById("InsertRecordOC_news_print").onchange=ocProductsCheck;

</script>

 

Hope it helps.

Link to post
Share on other sites

Thanks, but it didn't work.

 

I had tried a very similar script as well but it also didn't work.

 

*I wonder if the rule to disable the box is somehow causing a bug that prevents the checkbox from not being unchecked?

 

** Still looking for a solution if anyone has an idea. :(

 

Thanks

Geoff

 

 

 

Hi Geoff,
 
You can use following code in the footer field: 
 
<script>
function ocProductsCheck() {
if (document.getElementById('InsertRecordOC_news_print').checked.==false) 
   {
    document.getElementById("InsertRecordOC_news_eletter").checked=false;
   }
}
document.getElementById("InsertRecordOC_news_print").onchange=ocProductsCheck;
</script>
 
Hope it helps.

 

Link to post
Share on other sites
  • Solution

OK - I circled around to this one more time, and really looked at the code that was provided by iren (thx again).

 

I discovered there was an extra "." at the end of the first if statement ".checked.==false)"... I removed it, tested, and it now works. So.. thanks very much again Iren.

 

 

Here's the working code.

 

<SCRIPT LANGUAGE="JavaScript">
function ocProductsCheck() {
if (document.getElementById("InsertRecordOC_print").checked==false)
   {
    document.getElementById("InsertRecordOC_newsletter").checked=false;
   }
}
document.getElementById("InsertRecordOC_print").onchange=ocProductsCheck;
</script>

 

Best regards,

 

Geoff

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.
Note: Your post will require moderator approval before it will be visible.

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...
×
×
  • Create New...