|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello all 1st Post, hopefully someone can shed some light on this one.
I have a form that I would, for a few sections, to have a button that will prompt the user to how many "policy #'s" they are going to need to add to this form. I believe I need JavaScript for this form. So all this code below would be hidden until the user clicks on the button and answers how many needed to add. Also I would need to appened a _1, _2, _3 etc to the end of the names once they choose the amounts.... If there is an easier lang to do it in please let me know as well...thanks in advance The following code is what I am working with: HTML Code:
<div class="section">Section 4: Client Group or Policy Number Access</div> <br> <table border="1" width=100%> <th>Platform</th> <th>Policy Number or DIV/Group</th> <th>Customer Number / Master Group</th> <tr> <td><center><select name="policy_type1"><option Value=""selected>Select Policy Platform<option Value="ces">CES<option Value="prime">PRIME<option Value="cosmos">COSMOS</select></center></td> <td><center>Policy Numer or DIV/Group<input type="text" name="policy1"></center></td> <td><center>Customer Number / Master Group<input type="text" name="customer1"></center></td> </tr> </table> |
|
#2
|
||||
|
||||
|
In other words, you need to add dynamically new rows in a table?
|
|
#3
|
|||
|
|||
|
I belive so, JScript is not my forte. So basically under that step there will be nothing but a button. Then once the users clicks the button, it will prompt for how many...
If they choose 4, i want to have 4 copies of the same code i encluded but changing the names to like i said _1 , _2 etc... |
|
#4
|
||||
|
||||
|
I can make this code for you, but, please, give me a Private Message to remaind me to do this tomorrow. I must go home now (it's 19 PM for me, so I must leave the office), and I am not sure I will have enough time tonight. But tomorrow I have, for sure.
|
|
#5
|
|||
|
|||
|
- - - -
Last edited by James Gatka; 07-31-2006 at 01:41 PM. |
|
#6
|
||||
|
||||
|
better use cloneNode(true) method, James. It will make the code much much shorter.
|
|
#7
|
||||
|
||||
|
Quote:
|
|
#8
|
||||
|
||||
|
Here's your code. Is it Ok for you?
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
var clone;
var tag =['select','input']
function addRows(){
var n = prompt('How Many?','input a number');
var rows = document.getElementById('mytab').getElementsByTagName('tr');
var root =rows[0].parentNode;
for(var i=0;i<n;i++){
for(var j=0;j<tag.length;j++){
var el=clone.getElementsByTagName(tag[j]);
for(var k=0;k<el.length;k++){
el[k].name=el[k].name.replace(/\d/g,'')+rows.length;
}
}
root.appendChild(clone);
clone=rows[rows.length-1].cloneNode(true)
}
}
onload = function(){
clone = document.getElementById('mytab').getElementsByTagName('tr')[1].cloneNode(true);
}
</script>
</head>
<body>
<form>
<table id="mytab" border="1" width=100%>
<th>Platform</th>
<th>Policy Number or DIV/Group</th>
<th>Customer Number / Master Group</th>
<tr>
<td><center><select name="policy_type1"><option value="" selected>Select Policy Platform<option Value="ces">CES<option Value="prime">PRIME<option Value="cosmos">COSMOS</select></center></td>
<td><center>Policy Numer or DIV/Group<input type="text" name="policy1"></center></td>
<td><center>Customer Number / Master Group<input type="text" name="customer1"></center></td>
</tr>
</table>
<br>
<br>
<input type="button" value="How many ?" onclick="addRows()">
</form>
</body>
</html>
|
|
#9
|
|||
|
|||
|
Awesome...
Thanks... U Da Man.... I can reuse this on other part of the form.... Was getting so fustrated with my code not working and i see where i goofed...thanks a ton!!!!
|
|
#10
|
||||
|
||||
|
Quote:
|
|
#11
|
|||
|
|||
|
yes tons....running a script on the form now...and everything is working great...you helped a ton...
THANKS AGAIN! |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|