Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to set/get a bootstrap select items index

How to set/get a bootstrap select items index

How to set/get a bootstrap select items index

Just started using PHP/MySql to convert old Access program. Using Bootstrap to speed things up. Generally it is going ok, except for using the Select input

In the data table dayofweek is stored as an integer (1=Monday etc).

I can get back that value ok, but am struggling with trying to show it as selected item in a Bootstrap Select input where the options are "Monday", "Tuesday"..."Sunday"

I assume it must be done with Javascript using the value from the database to set the index of the options, but have been struggling to see how this is done.

Similarly I need to convert the selected value back to the index to write back to the table.

I thought Google might have been my friend, but haven't found anything so far.

Can anyone give me a clue?


RE: How to set/get a bootstrap select items index

Selects have a property called selectedIndex. You can use that to get or set the "selected" item for the select by making it equal to a specific number.

selectObj.selectedIndex=3; Sets the item with index 3 to be selected and shown in the dropdown as selected.
note indexes start at 0. So index 3 refers to the fourth item in the Select list.

Beyond that, when submitting the form to PHP, a Select will submit the value of the currently selected item. As long as the value property of the <option> element has the index value, you should not need to do anything else.


<select name="myselect">
<option value="1">Monday</option> <option value="2">Tuesday</option> <option value="3">Wednesday</option>
... </select>

Phil AKA Vacunita
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close