Click to See Complete Forum and Search --> : dropdown list question


jennyj
09-01-2003, 07:27 AM
I appologize if this has been asked before, but I can't seem to find the answer.
Wasn't sure whether to post this here on in the ASP forum, as it's a mix of both, but I hope someone here can help me

I have a form with a drop down box. This drop down is populated from a database - no problem

What I want to happen is when a user chooses a value from the dropdown box, I would like to display a corresponding value (also from the database)

I want to be able to do this with onchange, as the submit button is used to post the whole of the form to the database.
I have tried using this.form.submit(); within the select tag, but get an error "Object does not support this property or method"

(btw, I know this will not work for users with javascript disabled, but for this application it is not a concern)

Can anyone talk me through this step by step, as my JavaScript is a little rusty-especially in conjunction with ASP

Thanks
JennyJ

Khalid Ali
09-01-2003, 08:36 AM
you will have to submit the form to the asp page for this to work.(the code you had should have worked)

this should do it for you,logically what you want is for m to be submitted when user selcts a value in the list box or when an onchange is triggered in the listbox.The code below will work...

<script type="text/javascript">
<!--
function Process(val){
var frm = document.getElementById("form1");
if(val!="-1"){//do any of your validations here
frm.submit();
}else{
//show an appropriate alert message here
}
}
//-->
</script>
</head>

<body class="body">
<form id="form1" action="" onsubmit="">
<input type="text" name="t1"/>
<select name="lb" onchange="Process(this.options[this.selectedIndex].value);">
<option value="-1" >1</option>
<option value="1" >1</option>
<option value="2" >2</option>
<option value="3" >3</option>
</select>
<input type="button" value="process" onclick="Process()"/>
</form>

jennyj
09-01-2003, 09:02 AM
thanks for the quick reply, Khalid.

either I haven't understood your code, or I haven't asked my question clearly enough.

My form has in fact got 12 drop down boxes, but just focussing on the first one fot the moment - I currently use
<form name="form1" method="post" action="select.asp?team_name=<%=request("team_name")%>&team_points=<%=request("team_points")%>">
<select name="horse_1">
<%
do while not rs.eof and iCount < rs.PageSize
%>
<option value="<%=rs("horse")%>"><%=rs("horse")%></option>
<%
rs.movenext
iCount = iCount + 1
loop
%>
</select>


earlier on in the script, I have used
If Request.Form("submit") = "submit" Then
SQL = "UPDATE tblteam set blahblahblah"
which is why I don't want to submit the form onchange, I don't want to submit the form until all the dropboxes are filled in

Sorry about this, I'm a bit of a newbie at Javascript- if your code works in the way i've explained, can you talk me through it - I don't really understand what's happening

Thank you
JennyJ

Khalid Ali
09-01-2003, 09:24 AM
Sure I 'll try....:D (if my explaination is a bit fuzzy,then its too early..)
see you can not send information to asp page without submitting the page.So you will have to do that.
Second what you can do is add another piece of condition which makes sure that you have submitted the form but its not for update the db rather its for running a search query.
What you can do is add a hidden field in the form and whenever you want to run a query because some one selected a value in the list box set some pre determined value to that hidden field and when some one submits the form by clicking the submit button make sure this hidden field is empty..

jennyj
09-01-2003, 10:10 AM
I have tried using onchange="this.form.submit();" within a select tag, but get an error "Object does not support this property or method"

can anyone tell me why?
JennyJ

BestZest
09-01-2003, 10:31 AM
With this code...

<form method="post" action="somepage.html">
<select onchange="this.form.submit()">
<option>hello
<option>goodbye
</select>

...I got no error in either Netscape 7.0 or Internet Explorer 6.0. Maybe you didn't have the action or method in the 'form' tag.
If it still doesn't work post the whole form you're trying to submit and I'll have a look.

BestZest

jennyj
09-01-2003, 10:47 AM
Hi BestZest, thanks for your quick reply.
The form is actually an ASP form, and my dropdown box is populated from a database. The form worked fine with just a standard form submit button, so I know thats not the problem. The problem occurred when I tried adding the onchange code
This is (part of)what I have at the moment

<form name="form1" method="post" action="select.asp?team_name=<%=request("team_name")%>&team_points=<%=request("team_points")%>">
<select name="horse_1" onchange="this.form.submit();">
<%
do while not rs.eof and iCount < rs.PageSize
%>
<option value="<%=rs("horse")%>"><%=rs("horse")%></option>
<%
rs.movenext
iCount = iCount + 1
loop
%>
</select>

BestZest
09-01-2003, 11:12 AM
Ahh hah! I think I might have it.
OK. I think, because within the asp code you use " (double quotes), and you start the action attribute with ", it might be causing an error.
You could try this:

action='select.asp?team_name=<%=request("team_name")%>&team_points=<%=request("team_points")%>'

Although I'm not to hot on ASP, and I dont have acces to an ASP server, so this is a guess. In fact it might not be it at all, because asp is compiled on the server :confused: !

BestZest

jennyj
09-01-2003, 11:17 AM
tried that - still the same error! any other thoughts?

BestZest
09-01-2003, 11:28 AM
you couldn't post the code created by the asp script on the combo box page (you can get this by right clicking then View Source) could you?

BestZest