Click to See Complete Forum and Search --> : [RESOLVED] JavaScript Button Option


ChiPhiZD
07-31-2006, 10:03 AM
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:

<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>

Kor
07-31-2006, 10:17 AM
In other words, you need to add dynamically new rows in a table?

ChiPhiZD
07-31-2006, 10:27 AM
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...

Kor
07-31-2006, 10:45 AM
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.

James Gatka
07-31-2006, 11:01 AM
- - - -

Kor
07-31-2006, 11:06 AM
better use cloneNode(true) method, James. It will make the code much much shorter.

Kor
07-31-2006, 04:15 PM
- - - -
Why did u erased your code, James?... It was good. I just wanted to tell you that you might have use another method.

Kor
08-01-2006, 04:10 AM
Here's your code. Is it Ok for you?

<!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>

ChiPhiZD
08-01-2006, 12:12 PM
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!!!!

:) :) :) :) :)

Kor
08-01-2006, 03:45 PM
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!!!!

:) :) :) :) :)

I guess it was the part whch supposes to re-name the form elements. I agree it's the most important... ok, now, I am glad I was of any help for u :)

ChiPhiZD
08-01-2006, 06:02 PM
yes tons....running a script on the form now...and everything is working great...you helped a ton...

THANKS AGAIN!