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

Updating text field / On Change

Status
Not open for further replies.

ScottMusich

Programmer
Mar 25, 2002
22
0
0
US
I use MX and i have a form with a list (first Name). When I selec the list I want the other text field to put in the corresponding last name from the database in the field on the form...

I know I need to use an OnChange function but not sure exactly how to grab the second field from the database based on the users selection.

Thanks

Scott Musich
Online Editor
 
ScottMusich, what server-side scripting are you using?? Coldfusion, ASP, CGI??

If its coldfusion, then something like: <input type=&quot;textfield&quot; name=&quot;somename&quot; value=&quot;#firstname#&quot;>

This will have the value read from the dB, just make sure the onChange is called.

The following example will load a name into the textfield depending on what the drop-down selection was:


<!-- This script will pass a value from the drop-down choice to the textfield. -->

<html>
<head>
<title>Passes Value From the Drop-Down Choice To the Textfield</title>
<meta name=&quot;author&quot; content=&quot;Ketan V. Mehta&quot;>

<script language=&quot;javascript&quot;>
function displ() {
//if the forms element is 0 (the first one) then return false; do nothing.
if(document.myFORM.valu.options[0].value == true) {
return false
}
else {
//otherwise, place the appropriate <option value> in the texfield from the drop-down menu.
document.myFORM.textfield.value=document.myFORM.valu.options[document.myFORM.valu.selectedIndex].value;
}
return true;
}
</script>
</head>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; width=&quot;75%&quot;>
<tr>
<td width=&quot;100%&quot;>
<form name=&quot;myFORM&quot; onClick=&quot;return displ();&quot;>
<select name=&quot;valu&quot; size=&quot;1&quot;>
<option value>Choose One</option>
<option value=&quot;MT001&quot;>MT0001 | Copper Cable Shield 1</option>
<option value=&quot;MT002&quot;>MT0002 | Copper Cable Shield 2</option>
<option value=&quot;MT003&quot;>MT0003 | Copper Cable Shield 3</option>
</select>
<input type=&quot;text&quot; name=&quot;textfield&quot; readonly>
</form>
</td>
</tr>
</table>
<p><font color=&quot;#D3342C&quot; size=&quot;2&quot; face=&quot;Verdana&quot;>Select a value for the drop down
and watch as the appropriate <option value> is placed into the checkbox.</font></p>
<p><font color=&quot;#D3342C&quot; size=&quot;2&quot; face=&quot;Verdana&quot;>For instance if <strong><option
value=&quot;Some Text Here&quot;>Click Me</option></strong> is selected,
then the value of the option (Some Text Here) is placed in the textfield.</font></p>
</body>
</html>


[sub]Reality continues to ruin my life...[sub]
 
Sorry - I am using ASP. I will look at your suggestion closer and try it out

thanks

Scott Musich
Online Editor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top