[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Show text if checkbox ticked (cross browser solution) PHP

Posted on 2006-06-16
9
Medium Priority
?
203 Views
Last Modified: 2006-11-18
Hi

I need  to have a checkbox, and when the user checks this, then it will display other information (but only show if the box is checked by the user)

I did a search a found a solution, but it did not work in Netscape, only in IE and Mozilla.  I do need it to work in Netscape.

Could someone please tell me how to do this so that it will work in all major browsers.

Thanks

Debbie
0
Comment
Question by:debbieau1
  • 5
  • 4
9 Comments
 
LVL 10

Accepted Solution

by:
js_vaughan earned 2000 total points
ID: 16925278
Debbie,

I have tested this to work with IE, Netscape, Firefox, and Opera....


<html>
<head>
<title>Experts-Exchange</title>

<script language="javascript">
<!--

function toggleText(input){

    var block = document.getElementById("hiddentext");

    if (input.checked) {
        block.style.display = "block";
    } else {
        block.style.display = "none";
    }
}

// -->
</script>

</head>
<body>

<form name="your_Form">

    <input type="checkbox" name="togglebox" onClick="toggleText(this)"> Show Hidden Text
    <br>

    <p>I will always be visible.</p>
   
    <div id="hiddentext" style="display:none;">
        <p>I am hidden most of the time.</p>
    </div>

</form>

</body>
</html>
0
 
LVL 1

Author Comment

by:debbieau1
ID: 16925285
Fantastic!  Thanks.  Worked like a charm!

Debbie
0
 
LVL 10

Expert Comment

by:js_vaughan
ID: 16925290
Glad to be of help :-)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:debbieau1
ID: 16925302
I hope you don't mind if I ask one more question on this.  I know you have answered the question for me, but if it's not too much trouble could you tell me how to use multiple checkboxes on the one page, if it's not too much trouble
0
 
LVL 10

Expert Comment

by:js_vaughan
ID: 16925323
What's an example of your scenario?  For example, do you need 1 checkbox to control 1 hidden block, and a second checkbox to control a second block?
0
 
LVL 1

Author Comment

by:debbieau1
ID: 16925328
Yes, that would be ideal, then I could work out a lot myself from there.
0
 
LVL 10

Expert Comment

by:js_vaughan
ID: 16925370
<html>
<head>
<title>Experts-Exchange</title>

<script language="javascript">
<!--

function toggleText(input){

    var block;
   
            // Determine the correct block to adjust by looking at the checkbox's ID
    switch (input.id) {
   
        case "toggle1":
            block = document.getElementById("hiddentext1");
            break;
        case "toggle2":
            block = document.getElementById("hiddentext2");
            break;
        default:
            alert('Error in input.id');
    }

    // Adjust the block based on checked / unchecked
    if (input.checked) {
        block.style.display = "block";
    } else {
        block.style.display = "none";
    }
}

// -->
</script>

</head>
<body>

<form name="your_Form">

    <p>I will always be visible.</p>

    <input type="checkbox" name="togglebox" id="toggle1" onClick="toggleText(this)"> Show Block 1
    <br>
   
    <div id="hiddentext1" style="display:none;">
        <p>I am  block 1.</p>
    </div>
            
    <input type="checkbox" name="togglebox" id="toggle2" onClick="toggleText(this)"> Show Block 2
    <br>
   
    <div id="hiddentext2" style="display:none;">
        <p>I am block 2.</p>
    </div>

</form>

</body>
</html>
0
 
LVL 1

Author Comment

by:debbieau1
ID: 16925377
You're an absolute star!  Thank you works great.  I really appreciate you giving the extra help, especially considering I had already accepted your first answer.

Thanks again, this is such a help.
0
 
LVL 10

Expert Comment

by:js_vaughan
ID: 16925383
Glad to be here.  Cheers!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

830 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