Solved

Show text if checkbox ticked (cross browser solution) PHP

Posted on 2006-06-16
9
195 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 500 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jQuery Validate 4 36
Performance for Office 365 6 46
Simple Total function not working 8 30
Javascript Form Change 5 16
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 task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

786 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