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!

Modify JS function for a optionbox selected item 1

Status
Not open for further replies.

Dashley

Programmer
Dec 5, 2002
925
US
The function below is called from a onchange event from a different dropdownbox. The loadschedules function populates a schedules dropdownbox. Ultimately, a few other drop down selections are made, the form submits back to itself and all the previous selections are highlighted in their dropdown lists except for the one populated by this function. The value submitted from this dropdownlist is
"ScheduleID" as its name is ="ScheduleID".

How can I modify this function so it selects the correct item based on the value submitted
example": request.form("ScheduleID") 7923
or as passed ScheduleID=7923

the option value is: oNewOpt.value = aScheduleID[x]

somthing like
If oNewOpt.value = aScheduleID[x] == request.form("sheduleid") then
Item is Selected
End if

I'm not very fluent at JS

Thanks



Code:
function LoadSchedules(){
var x;
var oNewOpt;
while (document.getElementById("ScheduleID").length >0){
frm.ScheduleID.remove(frm.ScheduleID.length-1);
				}
oNewOpt = document.createElement('OPTION');
oNewOpt.text = "<All Schedules>";
oNewOpt.value = 0;
frm.ScheduleID.add(oNewOpt);
for (x=0; x < aSchedules.length; x++){
if (frm.evalid.options[frm.evalid.selectedIndex].value == aSchedEvalID[x]){
oNewOpt = document.createElement('OPTION');
oNewOpt.text = aSchedules[x];
oNewOpt.value = aScheduleID[x];
frm.ScheduleID.add(oNewOpt);
			}
		}
	}
 
That code is crazy to me, but here's what you want, after all your code:

Code:
function LoadSchedules(){
var x;
var oNewOpt;
while (document.getElementById("ScheduleID").length >0){
frm.ScheduleID.remove(frm.ScheduleID.length-1);
                }
oNewOpt = document.createElement('OPTION');
oNewOpt.text = "<All Schedules>";
oNewOpt.value = 0;
frm.ScheduleID.add(oNewOpt);
for (x=0; x < aSchedules.length; x++){
if (frm.evalid.options[frm.evalid.selectedIndex].value == aSchedEvalID[x]){
oNewOpt = document.createElement('OPTION');
oNewOpt.text = aSchedules[x];
oNewOpt.value = aScheduleID[x];
frm.ScheduleID.add(oNewOpt);
            }
        }
[!]frm.ScheduleID.value = "<%=request.form("sheduleid")%>"[/!]
    }


[monkey][snake] <.
 
Hi Monksnake,

Thanks.
I didnt write it. I'm dont do JS much. I inherited it on a page.

Your code works great. Is there a way to wrap it up in an if statement.

If request.form("sheduleid") <> "" then
frm.ScheduleID.value = "<%=request.form("sheduleid")%>"
end if
 
Yes, I'll use your example:

Code:
if ("<%=request.form("sheduleid")%>" != "") {
   frm.ScheduleID.value = "<%=request.form("sheduleid")%>"
}

[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top