Link to home
Start Free TrialLog in
Avatar of kingsfan76
kingsfan76

asked on

problem with hidden visibility <div>

the code in brief:
<div id='A' style="visibilty:hidden">
<table><tr><td>
  <input name="B" id="B1">
</table></div>
This section of code is not shown by default when the page loads.  It is shown when one of the redio buttons is checked in the page.  This part is ok.
The problem is I cannot get the value of the input field in javascript.  It tells me that 'document.form.B' is an [object], but when I get the value it returns [undefine].  Anyone knows why and how I can get the value?  or any better way for doing this?
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image


<input name="B" id="B1"> should be <input name="B" id="B1" name="B1">

Fritz the Blank
Oops, ignore that I meant:

<input name="B" id="B">

Fritz the Blank
ASKER CERTIFIED SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am also wondering about your input tag--you don't specify a type. That might be causing problems as well.

Fritz the Blank
Avatar of kingsfan76
kingsfan76

ASKER

Thanks for the help.  but i think i found what the problem is.  let me describe it.  In the html body,
<form name="form1">
.......some other codes

<div id="B"></div>  This is where it supposed to show
.......some more codes

<div id="A" style="visibility:hidden">
     <input name="test">
</div>

</form>

There's a javascript function that sets
B.innerhtml = A.innerhtml
not the exact code but u know what i mean.  so the block of code will show up dynamically.  i think the problem is after setting the innerhtml, there are two input fields of the same name "test" under the same form coz <div B> gets the exact same code from <div A>.  is there anyway to go around this? or i have to use a second form?
It is bad news to have more than one field with the same name. When you create the new block of dynamic code, you should set it up so that each new block gets an incremented number, so in Div A, the field is Test0, in Div B, Test1, and etc.

Fritz the Blank
Thanks for the help.  but i think i found what the problem is.  let me describe it.  In the html body,
<form name="form1">
.......some other codes

<div id="B"></div>  This is where it supposed to show
.......some more codes

<div id="A" style="visibility:hidden">
     <input name="test">
</div>

</form>

There's a javascript function that sets
B.innerhtml = A.innerhtml
not the exact code but u know what i mean.  so the block of code will show up dynamically.  i think the problem is after setting the innerhtml, there are two input fields of the same name "test" under the same form coz <div B> gets the exact same code from <div A>.  is there anyway to go around this? or i have to use a second form?
Please use the reload this question link in the upper left hand corner of this page. If you use the refresh from your browser it will repost your question.

I left you comment about your question above.

Fritz the Blank
Thanks for the help.  but i think i found what the problem is.  let me describe it.  In the html body,
<form name="form1">
.......some other codes

<div id="B"></div>  This is where it supposed to show
.......some more codes

<div id="A" style="visibility:hidden">
     <input name="test">
</div>

</form>

There's a javascript function that sets
B.innerhtml = A.innerhtml
not the exact code but u know what i mean.  so the block of code will show up dynamically.  i think the problem is after setting the innerhtml, there are two input fields of the same name "test" under the same form coz <div B> gets the exact same code from <div A>.  is there anyway to go around this? or i have to use a second form?
ooops.  no wonder.  thanks alot for ur help.

I got it now.  To avoid having the same name, i need to get rid of the code in <DIV A> after i tranfer it to <DIV B>
<script>
if (A.innerHTML != "")
{
   B.innerHTML = A.innerHTML;
   form1.Code.value = A.innerHTML;  //save the codes
   A.innerHTML = "";  //get rid of duplicate codes
}
else
   A.innerHTML = form1.Code.value;  //use the saved codes
</script>

<input type=hidden name="Code">
Since the problem is solved, then why the grade of C?

Fritz the Blank
grade changed to a "B" as I'm believing the asker answered the question himself. If this is the case I will also refund their point to them. Any objections to this change should be posted here and I will review. Thank You

DigitalXtreme
CS Moderator