p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript (http://p2p.wrox.com/forumdisplay.php?f=85)
-   -   Update textbox when List menu is Selected (http://p2p.wrox.com/showthread.php?t=5990)

rylemer November 10th, 2003 05:19 PM

Update textbox when List menu is Selected
 
Hi!
I have a list menu. then I pull the records in one of my table I created I called tblAssign there are 3 Columns in my table. ID, Assign and Email.
What I would like to do is When I selected the records in the list menu the textbox will be updated for ex. when I select "ELmer" in the list Menu the textbox will be shown my email adddres.

here is my codes hope you can help me thanks!!


<%Response.buffer=true%>
<%
  Set ObjCommand = Server.CreateObject("ADODB.Command")
  Set ObjCommand.ActiveConnection = ObjConn
      strSQLAssign= "SELECT assign,email from tblAssign Order by assign ASC;"
      ObjCommand.CommandText = strSQLAssign
  Set objRSt = ObjCommand.Execute
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<script language="javascript">
    function PutEmail(objThis){
        document.form1.txtEmail.value = document.form1.assign.sourceIndex(2);
    }
</script>
<body>
<form name="form1" method="post" action="">
  <select name="assign" size="1" OnChange=PutEmail(this);>
          <option><%=strassigned%></option>
          <%
               While not objRSt.EOF
                Response.Write "<option " & objRSt("email") & ">" & objRSt("assign") & "</option>" & "<br>"
                objRSt.MoveNext
            Wend
                objRSt.Close
             set objRSt = Nothing
          %>
   </select>
  <input name="txtEmail" type="text" id="txtEmail">
  <input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>

vknowles November 11th, 2003 12:15 AM

I think there are several problems in your code.

First, an OPTION object has a VALUE property. Also, the carriage-return you want is not an HTML <br>, but rather an ASCII 13.

So your option constructor should be like this:

Response.Write "<option value='" & objRSt("email") & "'>" & objRSt("assign") & "</option>" & chr(13)

Then, you need to access your selected item. A SELECT object has a couple of properties you can use. I will give two examples of how to change PutEmail().

Since you are passing "this", you can use it as the object reference.

//IE 4.0+, Netscape 6.0+
document.form1.txtEmail.value = objThis.value;

//IE 3.02+, Netscape 2.0+
document.form1.txtEmail.value = objThis.options[objThis.selectedIndex].value;

The newer version is much simpler, but it doesn't work with older browsers.



-Van
(Old dog learning new tricks...)

vknowles November 11th, 2003 12:20 AM

Actually, I'm not sure about using single-quotes to enclose the VALUE text. You might have to use double quotes, as in:

Response.Write "<option value=""" & objRSt("email") & """>" & objRSt("assign") & "</option>" & chr(13)

:)

-Van
(Old dog learning new tricks...)

rylemer November 11th, 2003 10:53 AM

yeah it works. you the man :) thanks ;)


All times are GMT -4. The time now is 04:02 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.