Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2004
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change table based on check box?

    I am not quite sure what to look for on the net - that's why I cannot quite find how to do this.

    Basically I have an html table with one input checkbox. If the check box is checked, I need two select drop-down menus to appear on the page.

    If the check box is NOT checked, then just display one select-box drop-down.

    I would like to enable the user to toggle back and forth (check it and uncheck it to change the page instantly).

    What exactly should I learn/look for on the net in order to develop this?

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <div id="div1"><p>Start Text</p></div>
    <input type="button" onClick="foo();" value="Click me to changethe start Text">
    
    function foo(){
    div1.innerHTML='<p>my new text</p>';
    {
    scroots
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished

  • #3
    New Coder
    Join Date
    Jan 2004
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This only seems to support IE. It works, and I am thankful to have a start.

    1.) How can I change it to switch back when clicked a second time?

    2.) Why doesn't it work in NetScape/Mozilla?

    The mozilla javascript debugger reports:

    error: div1 not defined.

    The final code I have is:

    PHP Code:
    <div id="div1"><p>Start Text</p></div>
    <
    input type="button" onClick="foo();" value="Change">
    <
    script language="javascript">
    function 
    foo(){
    div1.innerHTML='<p>my new text</p>';

    </script> 

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    var clicked=0;
    function foo(){
    if(click==0){
    alert('click1');
    click=1;
    }else{ //then click is not 0
    alert('click2');
    click=0;
    }
    if you run that once it will alert click 1, run it twice it will alert click 1 and click 2, three times it will alert click1,click2 and then click1.

    scroots
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Originally posted by botsko.net

    2.) Why doesn't it work in NetScape/Mozilla?
    IE makes the element ids and names as global variables.

    You should reference it the proper way like this:

    function foo(){
    document.getElementById('div1').innerHTML='<p>my new text</p>';
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •