Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
| Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 10th, 2003, 05:19 PM
Authorized User
 
Join Date: Jun 2003
Location: Marikina, , Philippines.
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to rylemer Send a message via MSN to rylemer Send a message via Yahoo to rylemer
Default 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>
  #2 (permalink)  
Old November 11th, 2003, 12:15 AM
Authorized User
 
Join Date: Jun 2003
Location: Lexington, KY, USA.
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

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...)
  #3 (permalink)  
Old November 11th, 2003, 12:20 AM
Authorized User
 
Join Date: Jun 2003
Location: Lexington, KY, USA.
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

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...)
  #4 (permalink)  
Old November 11th, 2003, 10:53 AM
Authorized User
 
Join Date: Jun 2003
Location: Marikina, , Philippines.
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to rylemer Send a message via MSN to rylemer Send a message via Yahoo to rylemer
Default

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
menu items visible always once heading selected. Hughesie78 ASP.NET 2.0 Professional 1 July 17th, 2008 01:22 AM
Selected value from dropdown menu wont display. mizjinx Classic ASP Databases 0 May 20th, 2007 08:24 PM
update list/menu value dynamically anjila Classic ASP Basics 1 February 5th, 2004 05:41 AM
display value of selected radio in the textbox hosefo81 Javascript How-To 1 February 1st, 2004 07:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.