Solved

Enable/Disable checkboxes

Posted on 2015-01-27
6
66 Views
Last Modified: 2015-01-28
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
Comment
Question by:Dzynit
  • 3
  • 2
6 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
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
 
LVL 14

Author Comment

by:Dzynit
Comment Utility
How would I do that to the current code?
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
Just add a simple if to test if disabled=false.

Cd&
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 14

Author Comment

by:Dzynit
Comment Utility
ok, so rather than a working example here, I'll go back to researching how to write the code. Thanks.
0
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
Comment Utility
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
 
LVL 14

Author Closing Comment

by:Dzynit
Comment Utility
Thank you very much. Worked perfectly. I'm very weak in javascript and jQuery so this was very helpful.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now