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

retaining the selected value in drop down box

Status
Not open for further replies.

Gill1978

Programmer
Jun 12, 2001
277
GB
Hi,

I have a drop down list box, which after the user selects a value reloads the page. However, it doesn't seem to retain the value seleted by the user it reverts back to the original value.

Can anyone tell me how the new value can be retained?

The drop down box code is:
<select size=&quot;1&quot; name=&quot;dropdown_menu&quot; onchange=&quot;reloadParent(this.value)&quot;>
<%
Dim i
For i = 1 to 12

Response.Write &quot;<option value='&quot;&i&&quot;'&quot;
If cInt(oRS(&quot;formnum&quot;)) = i Then Response.Write &quot; selected&quot;
Response.Write &quot;>&quot; & i & &quot;</option>&quot;
Next
%>
</select>



and the reload function looks like this:

function reloadParent(load){
if (load !== true) {
window.focus();
window.location.reload(false);
}
else {
};
}

Thanks

Julie
 
It goes back to the original value because you are comparing the value from the Recordset to see if it should be selected, rather than the value requested from the form... try using variables instead:
<%
dim varSelect
varSelect = Request.form(&quot;dropdown_menu&quot;)

if Len(Trim(varSelect)) = 0 then 'no value from form
varSelect = oRS(&quot;formnum&quot;)
end if

<select size=&quot;1&quot; name=&quot;dropdown_menu&quot; onchange=&quot;reloadParent(this.value)&quot;>
<%
Dim i
For i = 1 to 12

Response.Write &quot;<option value='&quot;&i&&quot;'&quot;
If cInt(varSelect) = i Then Response.Write &quot; selected&quot;
Response.Write &quot;>&quot; & i & &quot;</option>&quot;
Next
%>
</select>
 
Hi,

I've tried the above (code below) and it still brings back the original value of the drop box. Is there something wrong in the code?

<%

dim varSelect
varSelect = Request.form(&quot;dropdown_menu&quot;)

if Len(Trim(varSelect)) = 0 then 'no value from form
varSelect = oRS(&quot;formnum&quot;)
end if
Dim i
For i = 1 to 12

Response.Write &quot;<option value='&quot;&i&&quot;'&quot;
If cInt(varSelect) = i Then Response.Write &quot; selected&quot;
Response.Write &quot;>&quot; & i & &quot;</option>&quot;
Next
%>

Thanks

Julie
 
No, the idea is to bring the value last chosen as the selected one on the new screen rather than the value from the database. This appears to be an update page, so he wanted it to display the new choice rather than the old setting from the db, which it does.
-Tarwn ------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
I missed out the select statement, but now i get the following error;

Error Type:
Microsoft VBScript compilation (0x800A0400)
Expected statement
/Miller_Local/bdxCapSubSecDetails.asp, line 96
<select size=&quot;1&quot; name=&quot;dropdown_menu&quot; onchange=&quot;reloadParent(this.value)&quot;>


Browser Type:
Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)

Page:
GET /Miller_Local/bdxCapSubSecDetails.asp

The code changed to;

Error Type:
<%

dim varSelect
varSelect = Request.form(&quot;dropdown_menu&quot;)

if Len(Trim(varSelect)) = 0 then 'no value from form
varSelect = oRS(&quot;formnum&quot;)
end if

<select size=&quot;1&quot; name=&quot;dropdown_menu&quot; onchange=&quot;reloadParent(this.value)&quot;>
<%
Dim i
For i = 1 to 12

Response.Write &quot;<option value='&quot;&i&&quot;'&quot;
If cInt(varSelect) = i Then Response.Write &quot; selected&quot;
Response.Write &quot;>&quot; & i & &quot;</option>&quot;
Next

%>


Can't see what i'm doing wrong...
Julie
 
Is it possible there isn't a value in either your Request.Form or your recordset? I notice your using the recordset value if nothing was selected on the previous page.
-Tarwn ------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
I fixed the above problem, I had left in the original select above the new code. But it still selects the original database value after i select another value and then the page reloads. Could it have something to do with the reload function?

function reloadParent(load){
if (load !== true) {
window.focus();
window.location.reload(false);
}
else {
};
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top