Changing 'selected' Option in Select Dropdown before Submit

M

Monty

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.
 
D

Danny

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

Danny
 
L

Lee

Monty said:
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.

If you want the item that the users chooses to be selected when the
form is submitted, DON'T SET ANYTHING. The user has already set
the value.
If you want the form to be submitted as soon as they change the
selected value:

onchange="this.form.submit()"

If that doesn't work, the problem lies elsewhere.
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top