Solved

Enable/Disable checkboxes

Posted on 2015-01-27
6
68 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
ID: 40573538
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
ID: 40573711
How would I do that to the current code?
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 40573745
Just add a simple if to test if disabled=false.

Cd&
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 14

Author Comment

by:Dzynit
ID: 40573773
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
ID: 40574016
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
ID: 40575251
Thank you very much. Worked perfectly. I'm very weak in javascript and jQuery so this was very helpful.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

777 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