PDA

View Full Version : pass value to SELECT form object!


charon
09-26-2002, 10:22 AM
hi,

I want the SELECT form object to display what I pass to them. My code is as below:

<form name="frm" >
<br>
<div align="center"> <font size="1">
<select name="Project" onChange="Loadfile(document.frm.Project.value)">
<option value="">Select Project</option>
<option value="amp">Bukit Indah Ampang</option>
<option value="sri">Sri Hartamas</option>
<option value="pjp">Putrajaya Precinct 9</option>
<option value="pbp">Pusat Bandar Puchong</option>
<option value="pbp">Puchong Indah</option>
<option value="sij">Setia Indah Johor</option>
<option value="bij">Bukit Indah Johor</option>

</select>
</font></div>
</form>

function Loadfile(pageFile)
{
if (pageFile == "bij")
{
document.location="/setiahomes/bij/displaybij.asp?action=index&cid=0";
}
else if (pageFile == "amp")
{
document.location="/setiahomes/ampang/displayamp.asp?action=index&cid=0";
document.frm.Project.value = "amp"
}
else if (pageFile == "pjp")
{
document.location="/setiahomes/spj/displayspj.asp?action=index&cid=0";
document.frm.Project.value = "pjp"
}
else
{
document.location="/setiahomes/sij/displayamp.asp?action=index&cid=0";
}
}

The JV script code failed to do what I want it to be, that is when the OnChange event handler executes the Loadfile function, it will go to another project and I want the Select Option display the name of the project.

Thanks!

Roy Sinclair
09-26-2002, 03:36 PM
Your problem is that there's a disconnect between the page you start on and the page where you're headed.

This line: document.location="/setiahomes/ampang/displayamp.asp?action=index&cid=0"; starts a new web page loading and then the following line: document.frm.Project.value = "amp" attempts to set a value in the new page.

The basic problem is that it takes time to load a new page and the second line executes right after the first. That's not the only problem because when the new page loads the old page is removed from the browser so the second line is no longer present to run against the new page even if it didn't execute right away.

What you need to do is pass an additional parameter to the new page which tells it which select to display. document.location="/setiahomes/ampang/displayamp.asp?action=index&cid=0&project=amp"; and then have your ASP code set the default as it builds the next page.

charon
09-27-2002, 03:01 AM
Yup, you are right!! Thanks you~!!

whammy
09-27-2002, 03:15 AM
In addition to passing the name of the project ni the querystring, this will prepopulate your select dropdown:


<select name="Project" onChange="Loadfile(document.frm.Project.value)">
<option value="">Select Project</option>
<option value="amp"<% If PageFile = "amp" Then Response.Write(" selected=""selected""") %>>Bukit Indah Ampang</option>
<option value="sri""<% If PageFile = "sri" Then Response.Write(" selected=""selected""") %>>>Sri Hartamas</option>
<option value="pjp""<% If PageFile = "pjp" Then Response.Write(" selected=""selected""") %>>>Putrajaya Precinct 9</option>
<option value="pbp""<% If PageFile = "pbp" Then Response.Write(" selected=""selected""") %>>>Pusat Bandar Puchong</option>
<option value="pbp""<% If PageFile = "pbp" Then Response.Write(" selected=""selected""") %>>>Puchong Indah</option>
<option value="sij""<% If PageFile = "sij" Then Response.Write(" selected=""selected""") %>>>Setia Indah Johor</option>
<option value="bij""<% If PageFile = "bij" Then Response.Write(" selected=""selected""") %>>>Bukit Indah Johor</option>

</select>


However, since you have two values named "pbp" if that's selected, the second one in the dropdown will always be selected...