Solved

Show text if checkbox ticked (cross browser solution) PHP

Posted on 2006-06-16
9
197 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
[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
  • 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
Technology Partners: 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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

739 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