selecting option in static dropdown

P

phl

I have static html <select> dropdowns in my page. I need to be able to
select an item from the dropdown dynamically. I won't know which item
it will be till run time. I will parse the url, try match item and
select it from choosen dropdowns. such as the example below:

url= http://localhost/mysite.asp?country=Alaska

<script>

selectitem(item, dropdownid) {...}

</script>

<select id="countryddl" name="country">

<option value="Alaska">Alaska</option>

<option value=...>...</option>

</select>

I can write a js function to do this. The problem is that I don't know
where to call this function. It seems the only place I can do this is
from <body>, as this has the onload event associated with it, but I
dont' have access to the <body> tag, as the page i am working on is
pieced together at run time.<select> don't have a suitable event
associated with it to do this. I tried calling it from <script> but it
can't find the dropdowns, beucase they have not be rendered yet at
that stage.

So for this problem, I need to be able to dynamically generate
parameters for my javascript function based on what I find in url. I
need to call it somewhere so the javascript function will be called. I
can't see how I can do this. Have I missed something?

If I generate all my dropdowns dynamically instead I will be able to
solve this problem. Before I do so I would like to know if I can solve
this problem with the above method.

cheers

-P
 
D

David Mark

I have static html <select> dropdowns in my page. I need to be able to
select an item from the dropdown dynamically. I won't know which item
it will be till run time. I will parse the url, try match item and
select it from choosen dropdowns. such as the example below:

url=http://localhost/mysite.asp?country=Alaska

<script>

selectitem(item, dropdownid) {...}

</script>

<select id="countryddl" name="country">

<option value="Alaska">Alaska</option>

<option value=...>...</option>

</select>

I can write a js function to do this. The problem is that I don't know
where to call this function. It seems the only place I can do this is
from <body>, as this has the onload event associated with it, but I
dont' have access to the <body> tag, as the page i am working on is
pieced together at run time.<select> don't have a suitable event
associated with it to do this. I tried calling it from <script> but it
can't find the dropdowns, beucase they have not be rendered yet at
that stage.

So for this problem, I need to be able to dynamically generate
parameters for my javascript function based on what I find in url. I
need to call it somewhere so the javascript function will be called. I
can't see how I can do this. Have I missed something?

If I generate all my dropdowns dynamically instead I will be able to
solve this problem. Before I do so I would like to know if I can solve
this problem with the above method.

cheers

-P
 
D

David Mark

I have static html <select> dropdowns in my page. I need to be able to
select an item from the dropdown dynamically. I won't know which item
it will be till run time. I will parse the url, try match item and
select it from choosen dropdowns. such as the example below:

url=http://localhost/mysite.asp?country=Alaska

<script>

type="JavaScript" I presume.
selectitem(item, dropdownid) {...}

</script>

<select id="countryddl" name="country">

<option value="Alaska">Alaska</option>

<option value=...>...</option>

</select>

I can write a js function to do this. The problem is that I don't know
where to call this function. It seems the only place I can do this is
from <body>, as this has the onload event associated with it, but I
dont' have access to the <body> tag, as the page i am working on is

window.onload = myfunction;
 
T

Thomas 'PointedEars' Lahn

David said:
type="JavaScript" I presume.

Wrong, it has to be a media type.

<script type="text/javascript">
...
</script>


PointedEars
 
D

David Mark

Wrong, it has to be a media type.

<script type="text/javascript">
...
</script>

No kidding. I shouldn't have made it look like I an attribute. What
I meant was that the script was JavaScript, despite the fact that no
type was specified. I think we all know that there is no such thing
as <script type="JavaScript">. The closest thing to that is
language="JavaScript", which is deprecated.
 
T

Thomas 'PointedEars' Lahn

David said:
Wrong, it has to be a media type.

<script type="text/javascript">
...
</script>

No kidding. I shouldn't have made it look like I an attribute.
What I meant was that the script was JavaScript, despite the fact that
no type was specified. [...]

Oh, I see :) But "JavaScript" wouldn't be sufficient either ;-)


Regards,
PointedEars
 
T

Thomas 'PointedEars' Lahn

David said:
[...] Thomas 'PointedEars' Lahn [...] wrote:
]snip]
no type was specified. [...]

You have destroyed the context again.
Re-read what I said and perhaps you will see that "JavaScript"
perfectly describes the type of script in the block.

Your smiley detector is borken. But since you insist, that piece of
code you were referring to is syntactically valid (when ignoring the
ellipsis) in any ECMAScript implementation, not only JavaScript.
Which is what I *jokingly* referred to.


PointedEars
 
D

David Mark

David said:
[...] Thomas 'PointedEars' Lahn [...] wrote:
[snip]

Your smiley detector is borken. But since you insist, that piece of

I never know what to make of smileys.
code you were referring to is syntactically valid (when ignoring the
ellipsis) in any ECMAScript implementation, not only JavaScript.
Which is what I *jokingly* referred to.

Oh. I get it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,414
Latest member
GayleWedel

Latest Threads

Top