Solved

Enable/Disable checkboxes

Posted on 2015-01-27
6
78 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to dynamically set the form action using jQuery.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

628 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