Solved

Enable/Disable checkboxes

Posted on 2015-01-27
6
67 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

910 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

25 Experts available now in Live!

Get 1:1 Help Now