logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > Javascript and JS frameworks
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 02-01-2010, 02:05 AM   #1
smitho
 
Join Date: Dec 2007
Posts: 149
Default Count the number of dropmenues

Is there a way to count the number of dropmenus in a cell?

I have a simple JS that will add dropmenus to a cell but I need to make the name for each one I add unique. If I can count the number I could add a number to the name each time the function is run.

HTML Code:
<script language="javascript">
function nodetest(val,val2){
//alert(document.getElementById('cellone').firstChild);
var myclone = document.getElementById(val2).cloneNode(true);
document.getElementById(val).appendChild(myclone);
}
</script>

<table border="1" id="mytab">
<thead>
  <tr>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
  </tr>
</thead>
<tbody>
  <tr>
    <td id="cellone">
        <input type="button" value="+" onclick="nodetest('cellone', 'select1')" />
         <select name="select1" id="select1">
           <option>One A</option>
        <option>One B</option>
        <option>One C</option>
        </select></td>
    <td id="celltwo">
    <input type="button" value="+" onclick="nodetest('celltwo','select2')" />
    <select name="select2" id="select2">
    <option>Two A</option>
    <option>Two B</option>
    <option>Two C</option>
    </select></td>
  </tr>
</tbody>
</table>



smitho is offline   Reply With Quote
Old 02-01-2010, 04:20 AM   #2
smitho
 
Join Date: Dec 2007
Posts: 149
Default

Change the select menus to :

HTML Code:
<select name="select1.0" id="select1.0">
then use this JS:

Code:
function nodetest(val,val2){
//alert(document.getElementById(val).childNodes.length);
var myclone = document.getElementById(val2).cloneNode(true);
var newName = myclone.name.substring(0,myclone.name.length-2)+"."+(document.getElementById(val).childNodes.length-3);
myclone.setAttribute('name',newName);
myclone.setAttribute('id',newName);
document.getElementById(val).appendChild(myclone);
}
This will create:

HTML Code:
<td id="cellone">
        <input value="A" onclick="nodetest('cellone', 'select1.0')" type="button">
         <select name="select1.0" id="select1.0">
           <option>One A</option>
        <option>One B</option>
        <option>One C</option>
        </select><select name="select1.1" id="select1.1">
           <option>One A</option>
        <option>One B</option>
        <option>One C</option>
        </select><select name="select1.2" id="select1.2">
           <option>One A</option>
        <option>One B</option>
        <option>One C</option>
        </select><select name="select1.3" id="select1.3">
           <option>One A</option>
        <option>One B</option>
        <option>One C</option>
        </select></td>
smitho is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:58 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com