/    Sign up×
Community /Pin to ProfileBookmark

Newbie ?: Populating Select Box w/ Passed In Value?

Hello List!

I’m new to JavaScript and am having a little problem w/ getting my select box populated…

I’m passing in a ‘LocationID’ to this page and need to write a function to take that LocationID and populate the select box when the page is loaded.

Here’s my onload:

[CODE]<body topmargin=”0″ leftmargin=”0″ onunload=”javascript:closeWindows();” onload=”loadTopSVGVariables(document.forms[0].LocationID);loadBottomLocationID(document.forms[0].LocationID);”>[/CODE]

And the function I’m trying to get working:

[CODE]function loadBottomLocationID(LocationID){

if ( LocationID != null ){
document.forms[0].LocationID = new Option(LocationID);
}

}[/CODE]

And, lastly, my code for my select box:

[code=html]<tr>
<td ID=”MultipleSearch”>
<select name=”LocationID” multiple=”true” size=”25″ Width=”200″>
[/code]

[CODE]<%
if IsArray(arrLocs) then
bSelectOptions = true
for i = 0 to UBound(arrLocs, 2)
Response.Write “<option value=””” & arrLocs(0,i) & “””>” & arrLocs(1,i) & “</option>”
next
end if
%>[/CODE]

[code=html]
</select>
</td>
</tr>[/code]

So, what I want is to get the LocationID that is being passed in, and populate this value in the select box on the page…

Any help or assistance you could provide would be greatly appreciated!

Thanks in advance for your time and help!
-jiggy_g

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@FangOct 15.2007 — LocationID should be a string, or passing 2 strings to newOption
function loadBottomLocationID(LocationID){

if ( LocationID != null ){
document.forms[0].LocationID = new Option([I]textValue[/I], [I]valueValue[/I]);
}

}
Copy linkTweet thisAlerts:
@jiggygauthorOct 15.2007 — Thanks for the reply!

I think I'm getting closer...

When I use this:
[CODE]
function loadBottomLocationID(locationID){

var txt = "TEST";
document.form1.LocationID.options[0] = new Option(txt);
return true;

}
[/CODE]


The string "TEST" is showing up in my select box; however, if I set
[CODE]
var txt = locationId;
[/CODE]


Nothing is showing up in the select box....

Thoughts?

Thanks again for your help!
Copy linkTweet thisAlerts:
@FangOct 15.2007 — This is passing a reference to an object

[I]loadBottomLocationID(document.forms[0].LocationID)[/I]

The new option is a reference to the select ???
Copy linkTweet thisAlerts:
@jiggygauthorOct 15.2007 — OK, so I'm trying to do this a different way now since my last approach didn't seem to work....but, now I'm getting an 'Object expected' error on the following line:

[CODE]
<body topmargin="0" leftmargin="0" onunload="Javascript:closeWindows();" onload="loadTopSVGVariables(document.forms[0].LocationID);loadBottomLocationID(document.forms[0].LocationID, 'TheNameofTheStation', 'TheLocIDofTheStation', true);">
[/CODE]


As you can see, I changed what I'm passing into my function!

My new function:

[CODE]
function loadBottomLocationID(obj,text,value,selected) {
if (obj!=null && obj.options!=null) {
obj.options[obj.options.length] = new Option(text, value, false, selected);
}
}
[/CODE]


And my line in the .asp file where I'm passing it in:
[CODE]
Response.Write "<td><a href=""#"" onClick=""top.Shell.MainWorkSpace.TopWorkSpace.location='../Drawings/DrawGetByLocID.asp?LocID=" & aInfo(0,i) & "&DrawTypeID=-99';document.location='AssignBenchmarkRecord.asp?locationID="& aInfo(1,i) &"&stationName="& aInfo(8,i) &"&stationID="& aInfo(0,i) &"&true';"">" & aInfo(8,i) & "</a></td>"
[/CODE]


In the box that shows the error, it's showing the URL as: http://staging/AssignRecords?locationID=123&stationName=TEST-123&stationID=12345&true; however, when I click on the properties of the page once it's loaded it only shows: Address (URL): http://staging/AssignBenchmarkRecord.asp?

All help is GREATLY appreciated!! I need to get this working soon!

Thanks again!

-jiggyg
Copy linkTweet thisAlerts:
@FangOct 16.2007 — The function loadBottomLocationID works correctly.

To check the rest of the code requires a working link.
×

Success!

Help @jiggyg spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...