Click to See Complete Forum and Search --> : How to call a function when List box change
ahbeng123
April 24th, 2003, 10:36 PM
I am new in VB Script.
May i know how to call a function when the list box changed?
I want to retrieve data from database and populate it to the same page.
For example...... i want to call function Build_Name_List when the list box changed. After that, it will request data from database and populate to the same page. My page for users to key in details called name.asp.
<select name="listWafID" > ????? what is the command ???
<option value=""></option>
<%
Call Build_Name_List()
%>
Could somebody pls help ..........thx
columbus2003
April 25th, 2003, 12:42 AM
if you want to call client-side function, The following line will be OK.
<select name="listWafID" OnChange="Build_Name_List()">
But I think you are attemptin to call server-side function, How can it be possible without requesting from server. OnChange event of listBox occur at the client machine. So you have to reload your page with a different parameter when onChange event occur.
e.g.
<%
if (response("REQUEST_TYPE") = "CHANGE_LISTWAFID") then
Call Build_Name_List
end if
%>
<form id="frm1" ..... >
<select name="listWafID" OnChange="loadData()">
......
</select>
</form>
<script language="VBScript">
function loadData()
@@@frm1.action = "name.asp?REQUEST_TYPE=CHANGE_LISTWAFID"
......
frm1.submit()
end function
</script>
ahbeng123
April 25th, 2003, 04:15 AM
then how do i populate the data to name.asp
Example :.....
in my name.asp have text field --> txtName, txtAge..........
could i put document.form.txtName.value=rs('Name').....
my BUILD_NAME_LIST function are....
<%
Sub BUILD_NAME_LIST ()
Dim Name_ID,rsData, query
set rsData = Server.CreateObject("ADODB.Recordset")
rsData.ActiveConnection = CONN_STRING
query = "SELECT * FROM NAMETABLE
rsData.Source = query
rsData.CursorType = 0
rsData.CursorLocation = 2
rsData.LockType = 3
rsData.Open()
document.form.txtName.Value = rsData("Name")
End Sub
%>
But seem that this could not work....
Pls advice.. Thanks..
columbus2003
April 25th, 2003, 05:45 AM
<input type="text" id="txtName" value="<%=rsData("Name")%>">
value="<%=rsData("Name")%>" will be replaced with value="name1(value quired from database)" and send to client side. You will see when "View Source".
if you want to used just the same with your example, pls try like this.
<%
Sub BUILD_NAME_LIST ()
Dim Name_ID,rsData, query
set rsData = Server.CreateObject("ADODB.Recordset")
rsData.ActiveConnection = CONN_STRING
query = "SELECT * FROM NAMETABLE
rsData.Source = query
rsData.CursorType = 0
rsData.CursorLocation = 2
rsData.LockType = 3
rsData.Open()
%>
<SCRIPT language=....>
document.form.txtName.Value = "<%=rsData("Name")%>"
</SCRIPT>
<%
End Sub
%>
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.