...

View Full Version : clear text in conditional text area when radio unchecked



beliaz
09-02-2010, 06:49 AM
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:



<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!

Old Pedant
09-02-2010, 07:23 AM
Well, it's pretty inelegant, but you could do:


<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.

beliaz
09-02-2010, 11:12 AM
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!

Old Pedant
09-02-2010, 07:15 PM
Maybe something like this:


<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.

beliaz
09-06-2010, 07:12 AM
Thank You! Thank You! Thank You! :thumbsup:

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....




<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>

Philip M
09-06-2010, 07:41 AM
<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

beliaz
09-06-2010, 09:36 AM
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";
{
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>

Philip M
09-06-2010, 10:39 AM
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! :p But placing the { on a newline is quite often the source of obscure errors which turn up from time to time in this forum.

beliaz
09-06-2010, 09:49 PM
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?



<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>

beliaz
09-07-2010, 07:50 AM
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. :D

Philip M
09-07-2010, 08:08 AM
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.


<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.

beliaz
09-07-2010, 08:38 AM
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


<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>

beliaz
09-07-2010, 08:45 AM
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?

Philip M
09-07-2010, 08:58 AM
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!

beliaz
09-07-2010, 09:04 AM
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 :D
edit: or at least I still do!

beliaz
09-07-2010, 05:24 PM
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!


Phillip,

I'm afraid I don't understand what you mean. Where is clearradios(0)? I don't see it. And what other code should I copy? Is there a new one you mean? The last one I copied was in post 11.

Philip M
09-07-2010, 05:44 PM
Phillip,

I'm afraid I don't understand what you mean. Where is clearradios(0)? I don't see it. And what other code should I copy? Is there a new one you mean? The last one I copied was in post 11.

<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>

beliaz
09-07-2010, 07:10 PM
<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>
Oh, yes, I see it. But it doesn't fix the overall problem. That was from yesterday when I was trying a million different things I found on the web. But I'm glad you see it because it tells you that I'm out there trying to find solutions too, not just sitting around waiting for you guys to do it for me....well, for OldPendant to do it for me :D

Philip M
09-07-2010, 07:25 PM
..well, for OldPendant to do it for me :D

Hang Old Pendant's code! :D:D I did not attempt to modify his code as I thought he himself would be around pretty soon!

beliaz
09-24-2010, 04:00 PM
Hey guys,

Sorry for abandoning the thread like that, my father passed away and I haven't felt much like working the past few weeks.
I've spent the past two days trying different things.


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.

Yea, I see what you mean, I cleaned up that aspect of the code quite a bit without messing anything up :thumbsup:. I Still have the problem where if you choose 'sole proprietor' or 'partnership' on the first set of radials, (and then choose 'corporation') it automatically defaults the second set of radials to 'standard corporation' no matter what you pick in the second set.

I believe my problems have something to do with this snipet:


var b = 0

...as that's the starting point of the loop (I would think).

Current version uploaded here:
http://jpcomputerconsulting.com/Untitled-1.html

Here's where I'm at:



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function bizTypeClick(rb){
document.getElementById("corp0").style.display = "none";
document.getElementById("corp1").style.display = "none";
document.getElementById("corp2").style.display = "none";
document.forms[0].corpType[0].checked = false;
document.forms[0].corpType[1].checked = false;
document.forms[0].corpType[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 corpTypeClick(rb){
var choice = rb.value;
for ( var b = 0; b < 999999; ++b ){
var div = document.getElementById("corp"+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">
<div>

<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></p>
</div>

<div id="bizInfo0" style="display:none">
<p> This is my sole proprietorship info:
<input type="text" name="ownersName"></p>
</div>

<div id="bizInfo1" style="display:none">
<p> 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"></p>
</div>

<div id="bizInfo2" style="display:none">
<p>Please choose your corporation type:
<label><input type="radio" name="corpType" value="0" onClick="corpTypeClick(this)">Standard Corporation</label>
<label><input type="radio" name="corpType" value="1" onClick="corpTypeClick(this)">S-Corp</label>
<label><input type="radio" name="corpType" value="2" onClick="corpTypeClick(this)">LLC</label></p>
</div>

<div id="corp0" style="display:none">
<p> This is my corporation info.
<input type="text" name="stateOfIncorporation1">
<input type="text" name="yearOfIncorporation1"></p>
</div>

<div id="corp1" style="display:none">
<p>This is my S-Corp info.
<input type="text" name="stateOfIncorporation2">
<input type="text" name="yearOfIncorporation2"></p>
</div>

<div id="corp2" style="display:none">
<p>This is my LLC info.
<input type="text" name="stateOfIncorporation3">
<input type="text" name="yearOfIncorporation3"></p>
</div>

</form>
</body>

I'll stay at it and if I happen to come across an answer first, I will be happy to post back so maybe someone in the future won't have to go through hours of research.

I'm amazed that I'm the first person to ever want one radial set dependent on another, but after searching the net so much, I'm now positive I must be! :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum