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

Drop Down values triggering page changes? 1

Status
Not open for further replies.

smurfer

Programmer
Jun 8, 2001
57
US
I am trying to create a form which asks a series of q's the last of which triggers what questions follow from a set.
i.e.
<select name=&quot;age&quot;>How old are you?</select>
<option value=&quot;20&quot;>20-30</option>
<option value=&quot;30&quot;>+30</option></select>

If you answer 20-30, I want to then display a set of q's geared for that group, if +30 is chosen, a different set of q's is displayed.

I was thinking that I could simply use IF login to check for the value of &quot;age&quot; then dependant display the appropriate html code for the q's, however I am not sure how to get the page to change and resubmit itself after the value is selected? Not sure if this is the best way to do it since I will need to use same kind of login again inside the question ranges dependent on answers chosen. I was thinking an onchange() for the Drop Down calling a j-script function that will resubmit the page passing that value would work, but having issues with the resubmit code?
Thanks,
SM
 
I have done something similar. You can use this to force your submit.

select name=&quot;age&quot; onChange='document.formName.submit()'>How old are you?</select>
<option value=&quot;20&quot;>20-30</option>
<option value=&quot;30&quot;>+30</option></select>

If you want it to set the form action to a diffrent page

<form name=formName action=page2.asp ...

then I would use a function and you can set both at the same time. If you need some help with that also let me know.

Roj

 
Roj,
thank you very much for your help. Is there a way to keep the focus on the issue just changed after the page submits?
Thanks,
SM
 
I am not exactly sure what you mean by issue but I am assuming that you want to return the focus to the set of q's just answered. One way that comes to mind first is to use a hidden field to hold which was the last q answered. Then when the page submits you could check this field on the onLoad and use it to set the focus. So in this case I think you should change your submit script to a function and use the pass the value of what field you are on as a parameter.

<script language=javascript>
function subPage(lastPage){
document.formname.last.value=lastPage
document.formname.submit()
}
function setF()
document.formname.<%response.write(request.form(&quot;last&quot;))%>.focus()
}
</script>
then in the form
<input type=hidden name=last value=''>
select name=&quot;age&quot; onChange='subPage(&quot;age&quot;)'>How old are you?</select>
<option value=&quot;20&quot;>20-30</option>
<option value=&quot;30&quot;>+30</option></select>

So what I am trying to say is that you pass the value of which element you want to gain the focus when the page is submitted. If you have a hard time understanding this send me your email and I will email it to you as an asp page.

Roj



 
Roj,
I understand your concept however when I tried this on the initial load of the page, the last variable does not have a value so I am receiving an error on the setF() as it returns document.formname..focus where the last value should be between the dots but since it is null, nothing appears causing an error. Let me know if it's easier to send a sample page.
Thanks again..
 
I see the problem. Ok I think the easiest solution would just to have your asp check to see if there is a value before writing out your javascript. So you could either use the &quot;if isEmpty...&quot; or check to see that a value exsits &quot;if request.form(&quot;last&quot;)<>&quot;&quot;... &quot; This way if there is no value to use you will not even write out the java script and if there is you will. Let me know if this makes any sense..It's Monday and I am still on my first cup of coffee.

...if it all worked without any problems we would all be out of a job .

Roj
 
Here is the sample that I made. It is rought but I think you will get the idea. The only diffrence would be to make the textbox(last) hidden instead of text.


<% @language = &quot;vbscript&quot;%>
<%dim last
last = Request.Form(&quot;last&quot;)
%>
<html>
<head>
<script language=javascript>
function setL(here){
document.formName.last.value=here
}
function setF(){
<%if request.form(&quot;last&quot;)<>&quot;&quot; then
response.write(&quot;document.formName.&quot;&last&&quot;.focus()&quot;)
end if %>
}

</script>
</head>
<body action=test.asp onLoad=setF()>
<form name=formName id=formName method=post>
<select name=&quot;SrcSelect&quot; onChange=setL(&quot;SrcSelect&quot;)>
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
</select>
<input type=checkbox value=hey name=box onClick=setL(&quot;box&quot;)>Hey</input>
<input type=checkbox value=there name=box>ther</input>
<input type=checkbox value=what name=box>what</input>
<input type=checkbox value=upname=box id=checkbox1 name=checkbox1>up</input>
<input type=text name=last value=&quot;<%=last%>&quot;>
<input type=submit>

</form>


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top