Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 84
  • Last Modified:

Enable/Disable checkboxes

On this tool:
https://www.searchcommander.com/seo-tools/keyword-list-mashup/

There's a set of 5 checkboxes toward the bottom. The 5th one "Checking this box CHANGES this tool..." unchecks and disables the previous 4. If you uncheck that 5th, the other 4 re-enable.

Now I need to make the 4th one "Negative Match" uncheck and disable the first 3, yet if you check the 5th, still make all 4 uncheck and disable.

Using either the 4th or 5th only works as expected, but if I check the 4th, then try using the 5th, the enabling / disabling gets all messed up.

Here's the javascript I'm using:
<script type="text/javascript">
function uncheck(){
	var x=document.forms.keywordmarriage
	x['phrase'].checked=false
	x['phrase'].disabled= !x['phrase'].disabled
	x['exact'].checked=false
	x['exact'].disabled= !x['exact'].disabled
	x['modbroad'].checked=false
	x['modbroad'].disabled= !x['modbroad'].disabled
	x['negative'].checked=false
	x['negative'].disabled= !x['negative'].disabled
}
function uncheckthree(){
	var x=document.forms.keywordmarriage
	x['phrase'].checked=false
	x['phrase'].disabled= !x['phrase'].disabled
	x['exact'].checked=false
	x['exact'].disabled= !x['exact'].disabled
	x['modbroad'].checked=false
	x['modbroad'].disabled= !x['modbroad'].disabled
}
</script>

Open in new window


And here's the checkbox section:
			<input type="checkbox" name="phrase" value="ON" /> Add Phrase Match &nbsp;<input type="checkbox" name="exact" value="ON" /> Add Exact Match &nbsp;<input type="checkbox" name="modbroad" value="ON" /> Add Broad Match Modifier &nbsp;<input type="checkbox" name="negative" value="ON" onclick="uncheckthree()" /> Add Negative Match <br /><br />
			<input type="checkbox" name="links" value="ON" onclick="uncheck()"> &nbsp;Checking this box CHANGES this tool, so it will generate EXACTLY what you input. Do do not use with the Adwords match types. 

Open in new window

0
Dzynit
Asked:
Dzynit
  • 3
  • 2
1 Solution
 
COBOLdinosaurCommented:
You need to test the current stat of the checkboxes before you check or uncheck/disable them.  If you try to uncheck a checkbox that is already unchecked and disable it should generate an except because you cannot access a disabled checkbox unless you enable it first.

Cd&
0
 
DzynitAuthor Commented:
How would I do that to the current code?
0
 
COBOLdinosaurCommented:
Just add a simple if to test if disabled=false.

Cd&
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
DzynitAuthor Commented:
ok, so rather than a working example here, I'll go back to researching how to write the code. Thanks.
0
 
Rainer JeschorCommented:
Hi,
here is a working example.
http://jsfiddle.net/EE_RainerJ/aaxn7tyn/

function uncheck(){
	var x=document.forms.keywordmarriage
    var linkschecked = x['links'].checked;
    var hasBeenDisabled = x['phrase'].disabled || x['exact'].disabled || x['modbroad'].disabled;
    if (linkschecked) {
        if (!hasBeenDisabled) {
            x['phrase'].checked=x['exact'].checked=x['modbroad'].checked=x['negative'].checked=false;
            x['phrase'].disabled=x['exact'].disabled=x['modbroad'].disabled=x['negative'].disabled=true;
        }
        else {
            x['negative'].checked=false;
            x['negative'].disabled=true;
        }
    }
    else {
        x['phrase'].disabled=x['exact'].disabled=x['modbroad'].disabled=x['negative'].disabled=false;
    }
}
function uncheckthree(){
	var x=document.forms.keywordmarriage
    var negChecked = x['negative'].checked;
    if (negChecked){
        x['phrase'].checked=x['exact'].checked=x['modbroad'].checked=false;
        x['phrase'].disabled=x['exact'].disabled=x['modbroad'].disabled=true;        
    }
    else {
        x['phrase'].disabled=x['exact'].disabled=x['modbroad'].disabled=false;
    }
}

Open in new window

Not that nice and there is surely room for improvement but its quite late here, so no Oscars for code readability.
HTH
Rainer
0
 
DzynitAuthor Commented:
Thank you very much. Worked perfectly. I'm very weak in javascript and jQuery so this was very helpful.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now