By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,993 Members | 1,947 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,993 IT Pros & Developers. It's quick & easy.

Changing 'selected' Option in Select Dropdown before Submit

P: n/a
I use a SELECT dropdown as the nav interface for jumping to a chosen
page number. When I setup up the SELECT element on the page, I want to
show the user the current page number they are on, so, I put "selected"
next to the page number, as shown below:

-------------------------------

<form name="pick" method="post" action="showit.php">
<select name="pggo"
onChange="this.options[this.selectedIndex].selected;document.pick.submit();">
<option value="1">1</option>
<option value="2" selected>2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</form>

-------------------------------

The problem is that no matter what page number is chosen from the
dropdown, the passed value is always "2", because that's the "selected"
value above.

Is there any Javascript that I can add to the onChange statement above
that will change the 'selected' value from the current page number to
the one chosen by the user? I've tried a bunch of things, but, 2 is the
value that seems to always get passed. I'm not sure how to change the
selected value to the one chosen from the dropdown. Am I close with the
above code, or way off base?

Any help is much appreciated! I've spent about 4 hours searching and
trying to find out how to do this, but, nothing seems to work. Maybe
it's not possible?

Thanks.

Nov 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

Your plight seem to be with PHP, not with js, so, check in your PHP
script instead.

Danny
Nov 23 '05 #2

P: n/a
On 2005-11-20, Monty <mo****@hotmail.com> wrote:
I use a SELECT dropdown as the nav interface for jumping to a chosen
page number. When I setup up the SELECT element on the page, I want to
show the user the current page number they are on, so, I put "selected"
next to the page number, as shown below:

-------------------------------

<form name="pick" method="post" action="showit.php">
<select name="pggo"
onChange="this.options[this.selectedIndex].selected;document.pick.submit();">
<option value="1">1</option>
<option value="2" selected>2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</form>

-------------------------------

The problem is that no matter what page number is chosen from the
dropdown, the passed value is always "2", because that's the "selected"
value above.
Add onchange to each of the options?

aboce you say:
this.options[this.selectedIndex].selected


this part does nothing, what is it supposed to do?

Bye.
Jasen
Nov 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.