List Info

Thread: Selected Item




Selected Item
country flaguser name
United States
2007-04-04 07:17:02
Hello all. I have a select box with several options in it. I
need to
be able to set the "selected" property of the box
dynamically. The
user has already chosen another option on a different page
and that
value is stored in a database. As they arrive on the new
page I
extract the value already chosen, but need to set the select
box to
reflect that value. Any ideas? Thank you.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "JavaScript Forum" group.
To post to this group, send email to
JavaScript-Informationgooglegroups.com
To unsubscribe from this group, send email to
JavaScript-Information-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/JavaScript-Information
?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Selected Item
country flaguser name
United States
2007-04-04 07:52:11
If I understand what you're trying to do....you can store
the
extracted value in a hidden field and then loop through the
select box
values, when you hit a match, set the option to 'selected'.

On Apr 4, 8:17 am, "Window Frog" <m...deepskystudio.com> wrote:
> Hello all. I have a select box with several options in
it. I need to
> be able to set the "selected" property of the
box dynamically. The
> user has already chosen another option on a different
page and that
> value is stored in a database. As they arrive on the
new page I
> extract the value already chosen, but need to set the
select box to
> reflect that value. Any ideas? Thank you.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "JavaScript Forum" group.
To post to this group, send email to
JavaScript-Informationgooglegroups.com
To unsubscribe from this group, send email to
JavaScript-Information-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/JavaScript-Information
?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Selected Item
country flaguser name
United States
2007-04-04 09:52:33
Since it sounds like you are using a server side language
you may in
this case want to let the backed language help.

	<select name="col"
class="elIndent">
			<option value="">Select
One</option>
<?php
	while ($row = $cQuery->fetchRow()){
		if($row[0] == $_GET['col']){
			print "<option value='".$row[0]."'
selected>".$row[1]."</option>
n";
		}else{
			print "<option
value='".$row[0]."'>".$row[1]."</o
ption>n";
		}
	}
?>
		</select>

This uses the same 'loop-thru' idea that Isreal suggests. 
If the
select is being built from values in a database then just
make a check
to see if the user value matches a value in the list of
options.  If
the only thing your database contains is the user selection
and
everything else is static then Isreal's idea is probably the
best
option.

-ray


On Apr 4, 6:17 am, "Window Frog" <m...deepskystudio.com> wrote:
> Hello all. I have a select box with several options in
it. I need to
> be able to set the "selected" property of the
box dynamically. The
> user has already chosen another option on a different
page and that
> value is stored in a database. As they arrive on the
new page I
> extract the value already chosen, but need to set the
select box to
> reflect that value. Any ideas? Thank you.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "JavaScript Forum" group.
To post to this group, send email to
JavaScript-Informationgooglegroups.com
To unsubscribe from this group, send email to
JavaScript-Information-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/JavaScript-Information
?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Selected Item
country flaguser name
United States
2007-04-05 07:28:14
Awesome! I actually use .asp w/ vbscript, but looking at
what you put
down in PHP really helped. I never thought of it that way.
Great
stuff. Carrying that theme of checking to see if there is a
match and
then selecting it based on that... is there a way to check
more than
one value? For instance an array of values? I realize that
is a bit
off topic. I tried it and only got it to partially work. I
think my
"for i = 0 ...." was in the wrong location. Any
thoughts? Thanks.

On Apr 4, 10:52 am, "ray.d...gmail.com"
<ray.d...gmail.com> wrote:
> Since it sounds like you are using a server side
language you may in
> this case want to let the backed language help.
>
>         <select name="col"
class="elIndent">
>                         <option
value="">Select One</option>
> <?php
>         while ($row = $cQuery->fetchRow()){
>                 if($row[0] == $_GET['col']){
>                         print "<option
value='".$row[0]."'
selected>".$row[1]."</option>
> n";
>                 }else{
>                         print "<option
value='".$row[0]."'>".$row[1]."</o
ption>n";
>                 }
>         }
> ?>
>                 </select>
>
> This uses the same 'loop-thru' idea that Isreal
suggests.  If the
> select is being built from values in a database then
just make a check
> to see if the user value matches a value in the list of
options.  If
> the only thing your database contains is the user
selection and
> everything else is static then Isreal's idea is
probably the best
> option.
>
> -ray
>
> On Apr 4, 6:17 am, "Window Frog" <m...deepskystudio.com> wrote:
>
> > Hello all. I have a select box with several
options in it. I need to
> > be able to set the "selected" property
of the box dynamically. The
> > user has already chosen another option on a
different page and that
> > value is stored in a database. As they arrive on
the new page I
> > extract the value already chosen, but need to set
the select box to
> > reflect that value. Any ideas? Thank you.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "JavaScript Forum" group.
To post to this group, send email to
JavaScript-Informationgooglegroups.com
To unsubscribe from this group, send email to
JavaScript-Information-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/JavaScript-Information
?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )