...

View Full Version : Pass Id to function from event handler?



fuzzy1
04-11-2006, 02:11 PM
How MAY I pass the Id of textfield_X to function_Y from an event handler (onChange?) in dropdown_Z?

Ex:

//function_Y
function populateTextField(obj){
document.getElementById("ANYTextfield").value=obj;
}

//textField_X
<input type="text" name="ThisTextfield" id="ThisTextfield">


dropDown_Z
<select name="dropdownZ" onChange="populateTextField(this.value;">
<option value="01">Option 1</option>
<option value="02">Option 2</option>
</select>

I was thinking I might name the dropdown the same as the Textfield Id, but not sure how to pass that parameter to the function.

_Aerospace_Eng_
04-11-2006, 02:17 PM
Add another variable to the function_y.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function populateTextField(what,obj)
{
document.getElementById(what).value=obj;
}
</script>
</head>

<body>
<form action="#" method="post">
<input type="text" name="ThisTextfield" id="ThisTextfield">
<select name="dropdownZ" onchange="populateTextField('ThisTextfield',this.value);">
<option value="01">Option 1</option>
<option value="02">Option 2</option>
</select>
</form>
</body>
</html>

fuzzy1
04-11-2006, 02:42 PM
WOW THAT WAS FAST!

There's nothing more aggravating than asking a simple question and getting unnecessarily complicated answers! I've an operation which calls for a tweezers but have been getting answers recommending backhoes and bulldozers.

THANK YOU!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum