Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Increment Counter To Form Elements

Status
Not open for further replies.

jiggyg

Programmer
Oct 1, 2007
61
US
Hello List!

Newbie to javascript and have a few questions...

I want to number my FormElements to make them unique

So, I want the one named 'dupmerows_<tableid>' to be: 'dupmerows_<tableid>_<cnt>

So, I'll have a dupmerows_6_1, dupmerows_6_2

And, likewise with my other elements: counttype_<tableid>_<cnt> and countname_<tableid>_<cnt>


This is the mess I have so far :)
Code:
<script language="JavaScript">
function dupIt(itm){
	var dup = document.getElementById("dupme_" + itm);
	var clone = dup.cloneNode(true);
	var cloned = dup.appendChild(clone);
	cloned.childNodes[1].firstChild.selectedIndex=0;
	cloned.childNodes[2].firstChild.value=0;
	cloned.childNodes[1].firstChild.name=cloned.childNodes[1].firstChild.name.substring(0,11)	
	cloned.childNodes[1].firstChild.name=cloned.childNodes[1].firstChild.name + "_" + cnt
}
:
:
cnt = 0
 for i = 0 to UBound(aInfo, 2)
 :
 :
 Response.Write "<tr id=""dupmerows_" & aInfo(7,i) & "_" & cnt &""">"
 Response.Write "<th colspan=""5""></th>"
 Response.Write "<td>"'countType
 
  Response.Write "<select size=""1"" name=""CountType_" & aInfo(7,i) & "_" & cnt &""">"
    Response.Write"<option value="""">Please Select...</option>"
   
    For Each item In countType
      Response.Write"<option value ="& item & """"
	 if item = aInfo(5,i) then
	   Response.Write " selected"
	 end if
      Response.Write ">"& item &"</option>"
    Next
  Response.Write "</select>"
 Response.Write "</td>" 

 Response.Write "<td>"'count
   Response.Write "<input size=""10"" type=""text"" name=""countName_" & aInfo(7,i) & "_" & cnt &""" value=" & aInfo(6,i) & " onchange=""return numCheck(this)"">"

Response.Write "<input type=""button"" value=""Add"" onClick=""dupIt('" & aInfo(7,i) &"')"">"
:
:


How can I get it to uniquely name them???

ie: dupmerows_1_1, dupmerows_1_2...counttype_6_1, counttypes_6_2...countname_6_2, countname_6_2, etc??

Thanks in advance for your time and help!!
 
Missed something...also have this at the end of my code:
Code:
<script language="JavaScript">
 var = <% =cnt%>
</script>

Thanks,
-jiggyg
 
What a mess!! Please show ONLY Javascript and HTML source from the browser, not your ASP or any other server-side code.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top