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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing form data to a function

Status
Not open for further replies.

milams

Programmer
May 28, 2004
32
US
Hi All,

I'm not that this can be done in JavaScript, but what I'm trying to do is have a dropdown list with numbers in the list representing a quantity. I put an "onchange" on the dropdown list:
Code:
<script language="javascript">
var qty = document.testform.element.qty.value;

function testfor(){
for (var i=0; i<qty; i++) {
document.write('<input type="text" name= i size="20">' + '&nbsp' + i + '<br>');
}
} 
</script>

<form name="testform" method="POST">
<select size="1" name="qty" onchange="testfor()">
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
</select>
So when the user chooses a quantity it would call the function testfor(). Is this even possible? Well, the problem is that i'm not able to pass the value of "qty" to the function. I know that my syntax is wrong, but can I even do this? If so, can anyone help me with the syntax?
 
This should work for you.
Code:
<script language="javascript">
var qty = document.testform.element.qty.value;

function testfor([b]qty[/b]){
	for (var i=0; i< qty; i++) {
		document.write('<input type="text" name= i size="20">' + '&nbsp' + i + '<br>');
	}
}
</script>

<form name="testform" method="POST">
	<select size="1" name="qty" onChange="testfor([b]this.value[/b])">
		<option value="1">1</option>
		<option value="2">2</option>
		<option value="3">3</option>
	</select>
</form>

M. Brooks
 
Thank you, I knew I was missing something, but couldn't figure it out. Thank again for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top