-
javascript one
1) Page1.htm - contains only a submit button control.
2) User clicks this & sends page1 to Page2.asp
3) Page3.asp contains <select> and hidden field.
4) User selects from the combobox.
5) This selection text is placed into the hidden field.
6) The page then is then automatically submitted - to itself.
4-6 keep going in a loop, every time the user chooses an entry, the page reloads. Now when the page loads, the combobox shows the default first entry. What I'd like is for this to show trhe last selected entry. :)
What I've done is set up a body_onload event which loops through all the entries in the combobox and selects the one which matches the request pages hidden text field's text:
Code:
function SelectChosenGam() {
if (request.form("hidChosen") != "") {
var intCounter;
for(intCounter=0; intCounter<theForm.combo1.options.length; intCounter++) {
if (theForm.combo1.options[intCounter] == Request.Form("hidChosen")) {
theForm.combo1.selectedIndex = intCounter;
}
}
}
}
This works fine when the page2.asp page is submitting to itself. But then I realised that page1.htm submits to this page also & doesn't have the hidden field. How can I trap for this please ?
-
I couldn't make head nor tail of that!
Heres how I'd do it
<select name="select">
<option value="one" selected>one</option>
<optionvalue ="two" >two</option>
</select>
the above shows option one selected!
Use asp to write out the combo box!
and put a variable inplace of the selected
eg
dim one as string
print '<option value="one"' & one & '>one</option>
so all you do now is test what you got for your input, if you got a one then simply do
one = "selected"
print '<option value="one"' & one & '>one</option>
I'm not familiar with ASP so I don't know the syntax, but this is an adapted method of one I use for Perl!
If you need a more detailed explanation you'll have to wait until tommorow!!
-
Hi Progressive - thanks for that. You're right, I didn't explain that one too well, so had another attempt.
Please look again at the above as I've changed the wording of the question. It fails on the first if (request.form("hidChosen") != "") { line as it can't find the hidChosen field of page1.
Thanks ! :)
-
try this
Code:
onload="setTimeout('SelectChosenGam()', 1000)"
The onload event is not a particulary good method, when you are referencing form elements, and layers. As when the onload event fires these elements have not always been set!
This may be what is causing you problems!
Let me know how you get on!
-
I've stuck a hidden field in the page1.htm - this on'es been bugging me so though not too professional, I thought sod it ! :D
Thanks for the suggestions ;)