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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    clear text in conditional text area when radio unchecked

    Hi,
    I have a form setup so that selecting a radio button opens a specific text field. The problem is if the user starts to enter information, then switches to a different radio button (perhaps they chose the wrong radio to start), the text they already started to enter on the previous textfield doesn't get cleared. This will be a problem later when inserting to sql.

    Here is a summary of the code:

    Code:
    <head>
    <script type="text/javascript">
    function doClick(objRad){
    if (objRad.value=="0"){
    document.getElementById("textbox").style.display='block'; 
    }
    else{
    document.getElementById("textbox").style.display='none'; 
    }
    if (objRad.value=="1"){
    document.getElementById("textbox1").style.display='block'; 
    }
    else{
    document.getElementById("textbox1").style.display='none'; 
    }
    if (objRad.value=="2"){
    document.getElementById("textbox2").style.display='block';
    }
    else{
    document.getElementById("textbox2").style.display='none';
    }
    }
    </script>
    </head>
    <body>
    
    <form action="insert.php" method="post">
    <p>Please choose the business type:
    <input type="radio" name="rad" value="0" onclick="doClick(this)">
    Sole Proprietorship
    <input type="radio" name="rad" value="1" onclick="doClick(this)">
    Partnership
    <input type="radio" name="rad" value="2" onclick="doClick(this)">
    Corporation
    
    <div id="textbox" style="display:none">
    <input type="text" name="txt">
    This is my sole proprietorship info.</div>
    <div id="textbox1" style="display:none">
    <input type="text" name="txt">
    This is my partnership info.</div>
    <div id="textbox2" style="display:none">
    <input type="text" name="txt">This is my corporation info.
    </div>
    </form>
    </body>
    Any help is appreciated,
    Thanks in advance!

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Well, it's pretty inelegant, but you could do:
    Code:
    <script type="text/javascript">
    function doClick(objRad){
        if (objRad.value=="0"){
            document.getElementById("textbox").style.display='block'; 
        } else{
            document.getElementById("textbox").value = '';
            document.getElementById("textbox").style.display='none'; 
        }
        if (objRad.value=="1"){
            document.getElementById("textbox1").style.display='block'; 
        } else{
            document.getElementById("textbox1").value = '';
            document.getElementById("textbox1").style.display='none'; 
        }
        if (objRad.value=="2"){
            document.getElementById("textbox2").style.display='block';
        } else{
            document.getElementById("textbox2").value = '';
            document.getElementById("textbox2").style.display='none';
        }
    }
    </script>
    Would be more elegant to use a loop and use the form fields *AS* form fields, but w.t.h. Not that big a deal for this little bit of code.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Mar 2009
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Would be more elegant to use a loop and use the form fields *AS* form fields, but w.t.h. Not that big a deal for this little bit of code.
    Old Pedant,
    Thank You for your response. I've got to get some sleep but will try the code later today.
    One question...this is just a small snipet I used to keep this question simple, but the form I'm making is actually more complex and the java script keeps growing...conditional text fields within conditional text fields...yadayada
    You mentioned a 'loop'...not sure what that is, but if you can throw me an idea or a google search phrase so I can research it if you think it would be a better option...
    Thank You!

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Maybe something like this:
    Code:
    <head>
    <script type="text/javascript">
    function bizTypeClick(rb)
    {
        var choice = rb.value;
        for ( var b = 0; b < 999999; ++b )
        {
            var div = document.getElementById("bizInfo"+b);
            if ( div == null ) return; // no more matches
            if ( b == choice )
            {
                div.style.display = "block";
            } else {
                div.style.display = "none";
                var inps = div.getElementsByTagName("input");
                for ( var i = 0; i < inps.length; ++i )
                {
                    inps[i].value = "";
                }
            }
        }
    }
    </script>
    </head>
    <body>
    
    <form action="insert.php" method="post">
    <p>Please choose the business type:
    <label><input type="radio" name="bizType" value="0" onclick="bizTypeClick(this)">Sole Proprietorship</label>
    <label><input type="radio" name="bizType" value="1" onclick="bizTypeClick(this)">Partnership</label>
    <label><input type="radio" name="bizType" value="2" onclick="bizTypeClick(this)">Corporation</label>
    
    <div id="bizInfo0" style="display:none">
         This is my sole proprietorship info:
         <input type="text" name="ownersName">
    </div>
    <div id="bizInfo1" style="display:none">
        This is my partnership info.
        <input type="text" name="partner1">
        <input type="text" name="partner2">
        <input type="text" name="partner3">
        <input type="text" name="partner4">
    </div>
    <div id="bizInfo2" style="display:none">
        This is my corporation info.
        <input type="text" name="stateOfIncorporation"> 
        <input type="text" name="yearOfIncorporation">
    </div>
    </form>
    </body>
    The code in blue there is ultra simple: Just clears the value of all input fields in the non-chosen div's. In reality, you'd maybe want to look at the *types* of those input fields and act accordingly. For example, uncheck checkboxes instead of changing their values.
    Last edited by Old Pedant; 09-02-2010 at 07:18 PM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New Coder
    Join Date
    Mar 2009
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank You! Thank You! Thank You!

    Works beautifully.

    Is it possible I could also add radios into the invisible divs to break things down further? I'm trying something like below...the only problem is the divs involved in 'biz2Type' don't go away if you go back and make a different selection from the original 'bizType' radio boxes.....I understand why, but can't figure out a way to make it work....


    Code:
    <head>
    <script type="text/javascript">
    function bizTypeClick(rb)
    {
        var choice = rb.value;
        for ( var b = 0; b < 999999; ++b )
        {
            var div = document.getElementById("bizInfo"+b);
            if ( div == null ) return; // no more matches
            if ( b == choice )
            {
                div.style.display = "block";
            } else {
                div.style.display = "none";
                var inps = div.getElementsByTagName("input");
                for ( var i = 0; i < inps.length; ++i )
                {
                    inps[i].value = "";
                }
            }
        }
    }
    </script>
    <script type="text/javascript">
    function biz2TypeClick(rb)
    {
        var choice = rb.value;
        for ( var b = 0; b < 999999; ++b )
        {
            var div = document.getElementById("biz2Info"+b);
            if ( div == null ) return; // no more matches
            if ( b == choice )
            {
                div.style.display = "block";
            } else {
                div.style.display = "none";
                var inps = div.getElementsByTagName("input");
                for ( var i = 0; i < inps.length; ++i )
                {
                    inps[i].value = "";
                }
            }
        }
    }
    </script>
    </head>
    <body>
    
    <form action="insert.php" method="post">
    <p>Please choose the business type:
    <label><input type="radio" name="bizType" value="0" onclick="bizTypeClick(this)">Sole Proprietorship</label>
    <label><input type="radio" name="bizType" value="1" onclick="bizTypeClick(this)">Partnership</label>
    <label><input type="radio" name="bizType" value="2" onclick="bizTypeClick(this)">Corporation</label>
    
    
    <div id="bizInfo0" style="display:none">
         This is my sole proprietorship info:
         <input type="text" name="ownersName">
    </div>
    <div id="bizInfo1" style="display:none">
        This is my partnership info.
        <input type="text" name="partner1">
        <input type="text" name="partner2">
        <input type="text" name="partner3">
        <input type="text" name="partner4">
    </div>
    
    <div id="bizInfo2" style="display:none">
    <p>Please choose your corporation type:</p>
    <label><input type="radio" name="bizType2" value="0" onclick="biz2TypeClick(this)">Standard Corporation</label>
    <label><input type="radio" name="bizType2" value="1" onclick="biz2TypeClick(this)">S-Corp</label>
    <label><input type="radio" name="bizType2" value="2" onclick="biz2TypeClick(this)">LLC</label>
    </div>
    
    <div id="biz2Info0" style="display:none">
       <p> This is my corporation info.
        <input type="text" name="stateOfIncorporation"> 
        <input type="text" name="yearOfIncorporation"></p>
    </div>
    <div id="biz2Info1" style="display:none">
    	<p>This is my S-Corp info.
        <input type="text" name="stateOfIncorporation"> 
        <input type="text" name="yearOfIncorporation"></p>
    </div>
    <div id="biz2Info2" style="display:none">
    	<p>This is my LLC info.
        <input type="text" name="stateOfIncorporation"> 
        <input type="text" name="yearOfIncorporation"></p>
    </div>
    </form>
    </body>

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Code:
    <script type="text/javascript">
    function bizTypeClick(rb){
    
    document.getElementById("biz2Info0").style.display = "none";
    document.getElementById("biz2Info1").style.display = "none";
    document.getElementById("biz2Info2").style.display = "none";

    "I've just had a drink of warm tea that Danny [Mills] brought up at half-time". Football Commentator, Radio 5 Live

  • #7
    New Coder
    Join Date
    Mar 2009
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Phillip,
    Awesome..funny I thought of that before but guess I didn't use the correct syntax...
    One odd behavior...If you do go back and click on 'sole proprietor' or 'partnership' (away from 'corporation'), the biz2info divs do clear and go away, but if you try to go back to 'corporation' a second time, then the biz2info0 div is the only one that will show up no matter which corporation radio you choose.

    perhaps I'm still using the wrong syntax?

    Code:
    <head>
    <script type="text/javascript">
    function bizTypeClick(rb)
    {
    document.getElementById("biz2Info0").style.display = "none";
    document.getElementById("biz2Info1").style.display = "none";
    document.getElementById("biz2Info2").style.display = "none";
    {
        var choice = rb.value;
        for ( var b = 0; b < 999999; ++b )
        {
            var div = document.getElementById("bizInfo"+b);
            if ( div == null ) return; // no more matches
            if ( b == choice )
            {
                div.style.display = "block";
            } else {
                div.style.display = "none";
                var inps = div.getElementsByTagName("input");
                for ( var i = 0; i < inps.length; ++i )
                {
                    inps[i].value = "";
                }
            }
        }
    }
    }
    </script>
    <script type="text/javascript">
    function biz2TypeClick(rb)
    {
        var choice = rb.value;
        for ( var b = 0; b < 999999; ++b )
        {
            var div = document.getElementById("biz2Info"+b);
            if ( div == null ) return; // no more matches
            if ( b == choice )
            {
                div.style.display = "block";
            } else {
                div.style.display = "none";
                var inps = div.getElementsByTagName("input");
                for ( var i = 0; i < inps.length; ++i )
                {
                    inps[i].value = "";
                }
            }
        }
    }
    </script>
    </head>
    <body>
    
    <form action="insert.php" method="post">
    <p>Please choose the business type:
    <label><input type="radio" name="bizType" value="0" onclick="bizTypeClick(this)">Sole Proprietorship</label>
    <label><input type="radio" name="bizType" value="1" onclick="bizTypeClick(this)">Partnership</label>
    <label><input type="radio" name="bizType" value="2" onclick="bizTypeClick(this)">Corporation</label>
    
    
    <div id="bizInfo0" style="display:none">
         This is my sole proprietorship info:
         <input type="text" name="ownersName">
    </div>
    <div id="bizInfo1" style="display:none">
        This is my partnership info.
        <input type="text" name="partner1">
        <input type="text" name="partner2">
        <input type="text" name="partner3">
        <input type="text" name="partner4">
    </div>
    
    <div id="bizInfo2" style="display:none">
    <p>Please choose your corporation type:</p>
    <label><input type="radio" name="bizType2" value="0" onclick="biz2TypeClick(this)">Standard Corporation</label>
    <label><input type="radio" name="bizType2" value="1" onclick="biz2TypeClick(this)">S-Corp</label>
    <label><input type="radio" name="bizType2" value="2" onclick="biz2TypeClick(this)">LLC</label>
    </div>
    
    <div id="biz2Info0" style="display:none">
       <p> This is my corporation info.
        <input type="text" name="stateOfIncorporation"> 
        <input type="text" name="yearOfIncorporation"></p>
    </div>
    <div id="biz2Info1" style="display:none">
    	<p>This is my S-Corp info.
        <input type="text" name="stateOfIncorporation"> 
        <input type="text" name="yearOfIncorporation"></p>
    </div>
    <div id="biz2Info2" style="display:none">
    	<p>This is my LLC info.
        <input type="text" name="stateOfIncorporation"> 
        <input type="text" name="yearOfIncorporation"></p>
    </div>
    </form>
    </body>

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by beliaz View Post
    Phillip,
    Awesome..funny I thought of that before but guess I didn't use the correct syntax...
    One odd behavior...If you do go back and click on 'sole proprietor' or 'partnership' (away from 'corporation'), the biz2info divs do clear and go away, but if you try to go back to 'corporation' a second time, then the biz2info0 div is the only one that will show up no matter which corporation radio you choose.

    perhaps I'm still using the wrong syntax?
    <head>
    <script type="text/javascript">
    function bizTypeClick(rb) {
    document.getElementById("biz2Info0").style.display = "none";
    document.getElementById("biz2Info1").style.display = "none";
    document.getElementById("biz2Info2").style.display = "none";
    {

    You have an unwanted opening brace (and I now see an additional unwanted closing brace } at the end).

    You should always place the opening braces on the same line, thus

    function bizTypeClick(rb) {

    and not on the next line thus

    function bizTypeClick(rb)
    {

    There are several reasons for this, one being auto semi-colon insertion (too advanced to explain here), and another being the fault you have introduced. My learned friend Old Pedant does not subscribe to this! But placing the { on a newline is quite often the source of obscure errors which turn up from time to time in this forum.
    Last edited by Philip M; 09-06-2010 at 10:49 AM.

  • #9
    New Coder
    Join Date
    Mar 2009
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I made the changes recommended (see below) but still have the problem of only the 'biz2info0' div showing up, no matter what button selection, when revisiting the corporation options. One other thing I noticed is that if (when) you return to the second set of radio buttons, the last button the user checked (ie "LLC") also remains checked.

    Is there a line of code I could enter to the second script that would uncheck any selected bottons when the div visibility='none'?

    I am testing this on xampp only, and not a 'real' server..don't know if that would have any bearing?

    Code:
    <head>
    <script type="text/javascript">
    function bizTypeClick(rb){
    document.getElementById("biz2Info0").style.display = "none";
    document.getElementById("biz2Info1").style.display = "none";
    document.getElementById("biz2Info2").style.display = "none";
        var choice = rb.value;
        for ( var b = 0; b < 999999; ++b ){
            var div = document.getElementById("bizInfo"+b);
            if ( div == null ) return; // no more matches
            if ( b == choice ){
               div.style.display = "block";
            } else {
                div.style.display = "none";
                var inps = div.getElementsByTagName("input");
                for ( var i = 0; i < inps.length; ++i ){
                    inps[i].value = "";
                }
            }
        }
    }
    </script>
    <script type="text/javascript">
    function biz2TypeClick(rb){
        var choice = rb.value;
        for ( var b = 0; b < 999999; ++b ){
            var div = document.getElementById("biz2Info"+b);
            if ( div == null ) return; // no more matches
            if ( b == choice ){
                div.style.display = "block";
            } else {
                div.style.display = "none";
                var inps = div.getElementsByTagName("input");
                for ( var i = 0; i < inps.length; ++i ){
                    inps[i].value = "";
                }
            }
        }
    }
    </script>
    </head>
    <body>
    
    <form action="insert.php" method="post">
    <p>Please choose the business type:
    <label><input type="radio" name="bizType" value="0" onClick="bizTypeClick(this)">Sole Proprietorship</label>
    <label><input type="radio" name="bizType" value="1" onClick="bizTypeClick(this)">Partnership</label>
    <label><input type="radio" name="bizType" value="2" onClick="bizTypeClick(this)">Corporation</label>
    
    
    <div id="bizInfo0" style="display:none">
         This is my sole proprietorship info:
         <input type="text" name="ownersName">
    </div>
    <div id="bizInfo1" style="display:none">
        This is my partnership info.
        <input type="text" name="partner1">
        <input type="text" name="partner2">
        <input type="text" name="partner3">
        <input type="text" name="partner4">
    </div>
    
    <div id="bizInfo2" style="display:none">
    <p>Please choose your corporation type:</p>
    <label><input type="radio" name="bizType2" value="0" onClick="biz2TypeClick(this)">Standard Corporation</label>
    <label><input type="radio" name="bizType2" value="1" onClick="biz2TypeClick(this)">S-Corp</label>
    <label><input type="radio" name="bizType2" value="2" onClick="biz2TypeClick(this)">LLC</label>
    </div>
    
    <div id="biz2Info0" style="display:none">
       <p> This is my corporation info.
        <input type="text" name="stateOfIncorporation1"> 
        <input type="text" name="yearOfIncorporation1"></p>
    </div>
    <div id="biz2Info1" style="display:none">
    	<p>This is my S-Corp info.
        <input type="text" name="stateOfIncorporation2"> 
        <input type="text" name="yearOfIncorporation2"></p>
    </div>
    <div id="biz2Info2" style="display:none">
    	<p>This is my LLC info.
        <input type="text" name="stateOfIncorporation3"> 
        <input type="text" name="yearOfIncorporation3"></p>
    </div>
    </form>
    </body>
    Last edited by beliaz; 09-07-2010 at 03:36 AM. Reason: Changed code again

  • #10
    New Coder
    Join Date
    Mar 2009
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Don't you love it when you journey through a thousand websites to find a particular problem, and then finally, like the holy grail, you see a google meta description that is so narrative and true to your own problem that it MUST have a solution for you.......
    .......only to click on the link and find it is your own post from the previous day!

    anyway the problem still remains that because I have to use different *name*s (<<*am I doing that right*?) for each radio group (for db purposes), when I go back to the first set of radio buttons, (even though the div with the second group is properly hidden), the second group is retaining their value (at least I think this is the problem). So if you should go back to the second group, the result would be a paradox so sinister that only the first radio button's div would show no matter what radio button you selected.
    And, apparently, there's no written record of anybody in the English speaking, Internet posting world that's ever dealt with this.

  • #11
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    The code already supplied and repeated here works perfectly for me and I cannot understand your problem. All radio buttons in a group must have the same name.

    Code:
    <head>
    <script type="text/javascript">
    function bizTypeClick(rb){
    
    document.getElementById("biz2Info0").style.display = "none";
    document.getElementById("biz2Info1").style.display = "none";
    document.getElementById("biz2Info2").style.display = "none";
    
    document.forms[0].bizType2[0].checked = false;
    document.forms[0].bizType2[1].checked = false;
    document.forms[0].bizType2[2].checked = false;
    
        var choice = rb.value;
        for ( var b = 0; b < 999999; ++b )
        {
            var div = document.getElementById("bizInfo"+b);
            if ( div == null ) return; // no more matches
            if ( b == choice )
            {
                div.style.display = "block";
            } else {
                div.style.display = "none";
                var inps = div.getElementsByTagName("input");
                for ( var i = 0; i < inps.length; ++i )
                {
                    inps[i].value = "";
                }
            }
        }
    }
    
    function biz2TypeClick(rb) {
        var choice = rb.value;
        for ( var b = 0; b < 999999; ++b )
        {
            var div = document.getElementById("biz2Info"+b);
            if ( div == null ) return; // no more matches
            if ( b == choice )
            {
                div.style.display = "block";
            } else {
                div.style.display = "none";
                var inps = div.getElementsByTagName("input");
                for ( var i = 0; i < inps.length; ++i )
                {
                    inps[i].value = "";
                }
            }
        }
    }
    </script>
    </head>
    <body>
    
    <form action="insert.php" method="post">
    <p>Please choose the business type:
    <label><input type="radio" name="bizType" value="0" onclick="bizTypeClick(this)">Sole Proprietorship</label>
    <label><input type="radio" name="bizType" value="1" onclick="bizTypeClick(this)">Partnership</label>
    <label><input type="radio" name="bizType" value="2" onclick="bizTypeClick(this)">Corporation</label>
    
    
    <div id="bizInfo0" style="display:none">
         This is my sole proprietorship info:
         <input type="text" name="ownersName">
    </div>
    <div id="bizInfo1" style="display:none">
        This is my partnership info.
        <input type="text" name="partner1">
        <input type="text" name="partner2">
        <input type="text" name="partner3">
        <input type="text" name="partner4">
    </div>
    
    <div id="bizInfo2" style="display:none">
    <p>Please choose your corporation type:</p>
    <label><input type="radio" name="bizType2" value="0" onclick="biz2TypeClick(this)">Standard Corporation</label>
    <label><input type="radio" name="bizType2" value="1" onclick="biz2TypeClick(this)">S-Corp</label>
    <label><input type="radio" name="bizType2" value="2" onclick="biz2TypeClick(this)">LLC</label>
    </div>
    
    <div id="biz2Info0" style="display:none">
       <p> This is my corporation info.
        <input type="text" name="stateOfIncorporation"> 
        <input type="text" name="yearOfIncorporation"></p>
    </div>
    <div id="biz2Info1" style="display:none">
    	<p>This is my S-Corp info.
        <input type="text" name="stateOfIncorporation"> 
        <input type="text" name="yearOfIncorporation"></p>
    </div>
    <div id="biz2Info2" style="display:none">
    	<p>This is my LLC info.
        <input type="text" name="stateOfIncorporation"> 
        <input type="text" name="yearOfIncorporation"></p>
    </div>
    </form>
    </body>
    If you want to uncheck the previously selected Corporate radio buttons, add the lines in blue.

  • #12
    New Coder
    Join Date
    Mar 2009
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Dude, it's driving me bonkers lol. I just added the new lines in blue and still doesn't work.
    what happens is:
    if I choose 'sole prop' or 'partnership' first, and then choose 'corporation', I will get the 'standard corp, s-corp, llc' radios with only the 'standard corp' div, no matter which one I choose of that second group.
    if I (refresh page) and choose 'corporation' to start, then I will get the correct divs for 'standard, s-corp, llc' HOWEVER, if I go back and check 'sole prop, partnership', then when I go back to corporation, the only choosable div (of the second group) is 'standard corp' again

    ...so I guess the problem is when I choose 'sole prop, partnership' something is getting messed up.

    Here is the code again...I've looked over yours vs mine a few times now and don't see a difference.

    I'm going to upload to one of my hosted servers and check it out....

    Thankx for your patience btw
    Code:
    <head>
    <script type="text/javascript">
    function bizTypeClick(rb){
    document.getElementById("biz2Info0").style.display = "none";
    document.getElementById("biz2Info1").style.display = "none";
    document.getElementById("biz2Info2").style.display = "none";
    
    document.forms[0].bizType2[0].checked = false;
    document.forms[0].bizType2[1].checked = false;
    document.forms[0].bizType2[2].checked = false;
    
        var choice = rb.value;
        for ( var b = 0; b < 999999; ++b ){
            var div = document.getElementById("bizInfo"+b);
            if ( div == null ) return; // no more matches
            if ( b == choice ){
               div.style.display = "block";
            } else {
                div.style.display = "none";
                var inps = div.getElementsByTagName("input");
                for ( var i = 0; i < inps.length; ++i ){
                    inps[i].value = "";
                }
            }
        }
    }
    </script>
    <script type="text/javascript">
    function biz2TypeClick(rb){
        var choice = rb.value;
        for ( var b = 0; b < 999999; ++b ){
            var div = document.getElementById("biz2Info"+b);
            if ( div == null ) return; // no more matches
            if ( b == choice ){
                div.style.display = "block";
            } else {
                div.style.display = "none";
                var inps = div.getElementsByTagName("input");
                for ( var i = 0; i < inps.length; ++i ){
                    inps[i].value = "";
                }
            }
        }
    }
    </script>
    
    </head>
    <body>
    
    <form action="insert.php" method="post">
    <p>Please choose the business type:
    <label><input type="radio" name="bizType" value="0" onClick="bizTypeClick(this); ClearRadios(0)">Sole Proprietorship</label>
    <label><input type="radio" name="bizType" value="1" onClick="bizTypeClick(this); ClearRadios(1)">Partnership</label>
    <label><input type="radio" name="bizType" value="2" onClick="bizTypeClick(this)">Corporation</label>
    
    
    <div id="bizInfo0" style="display:none">
         This is my sole proprietorship info:
         <input type="text" name="ownersName">
    </div>
    <div id="bizInfo1" style="display:none">
        This is my partnership info.
        <input type="text" name="partner1">
        <input type="text" name="partner2">
        <input type="text" name="partner3">
        <input type="text" name="partner4">
    </div>
    
    <div id="bizInfo2" style="display:none">
    <p>Please choose your corporation type:</p>
    <label><input type="radio" name="bizType2" value="0" onClick="biz2TypeClick(this)">Standard Corporation</label>
    <label><input type="radio" name="bizType2" value="1" onClick="biz2TypeClick(this)">S-Corp</label>
    <label><input type="radio" name="bizType2" value="2" onClick="biz2TypeClick(this)">LLC</label>
    </div>
    
    <div id="biz2Info0" style="display:none">
       <p> This is my corporation info.
        <input type="text" name="stateOfIncorporation1"> 
        <input type="text" name="yearOfIncorporation1"></p>
    </div>
    <div id="biz2Info1" style="display:none">
    	<p>This is my S-Corp info.
        <input type="text" name="stateOfIncorporation2"> 
        <input type="text" name="yearOfIncorporation2"></p>
    </div>
    <div id="biz2Info2" style="display:none">
    	<p>This is my LLC info.
        <input type="text" name="stateOfIncorporation3"> 
        <input type="text" name="yearOfIncorporation3"></p>
    </div>
    </form>
    </body>

  • #13
    New Coder
    Join Date
    Mar 2009
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Phillip,
    I've uploaded it here:
    http://jpcomputerconsulting.com/Untitled-1.html
    you can see what I mean...

    edit: I just copied and pasted yours too btw, not working for me either. Are you going back and forth between the radio buttons more than once?
    Last edited by beliaz; 09-07-2010 at 08:51 AM.

  • #14
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    OK, I do now see the problem. Old Pedant - you wrote it, you fix it.

    I am having a little trouble sorting out the rather confusing bizInfo0, biz2Info0, biz2Info2 and so on. You might care to address this as well to give greater clarity.

    I get Lines 52 and 53 Object expected. That should point to the error. Is it ClearRadios(0)? No such function.

    Please copy the code Old Pedant and I have given you exactly and do not try to embellish it!
    Last edited by Philip M; 09-07-2010 at 09:04 AM.

  • #15
    New Coder
    Join Date
    Mar 2009
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    OK, I do now see the problem. Old Pedant - you wrote it, you fix it.

    I am having trouble sorting out the rather confusing bizInfo0, biz2Info0, biz2Info2 and so on. You might care to address this as well to give greater clarity.

    I get Line 52 Object expected. That should point to the error.
    hahahah...at least you know I'm not crazy
    edit: or at least I still do!


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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