Thread: show/hide div
View Single Post
Old 01-28-2013, 05:16 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Several errors.

For starters, when you clone your elements you are getting
Code:
<input type="text" name="user[]2"/><select name="type[]2" onchange="showHide(this)">
...
<input type="text" name="user[]3"/><select name="type[]3" onchange="showHide(this)">
...
If this page is intended to be submitted to a PHP page, then those names should either be just *ALL* "user[]" or they should be "user[2]", and so on.

Also, *ALL* your <div>s are getting the *SAME* id!!!! <div id="divselect">

That is *ILLEGAL* HTML! You will no longer be able to use document.getElementById("divselect") because of the illegality.

Also, you have this code:
Code:
         //hide the divs
         for(var i=0; i < divsO.length; i++) {
             divsO[i].style.display = 'block';
        }
Your comment says "hide the divs", but then your code SHOWS them all.

And I think you have goofed in another way: I think you have forgotten that you have *TWO TYPES* of <div>s!!

Code:
<div id="add_user" style="display: none;">
    ...
    <div id="add_user" style="display: none;">...</div>
</div>
and *BOTH TYPES* are included in your divsO variable!!!

In short, this is pretty much a complete hash and you need to almost start over and think about what you are after.
__________________
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.
Old Pedant is offline   Reply With Quote