MyBB Community Forums

Full Version: Using the index number of value in a select box
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
Is there a way to get access to the index number of a selected value in a select box?
To explain: in a select box you have, for example, 4 choices - 'Not Selected', 'Yes', 'No', 'Dont know'. When a User selects one (or left it without selecting - so that the 'Not Selected' is the "selected" value), the selected choice has a corresponding index number - 'Not Selected' is, usually, zero(0), 'Yes' is, usually, one(1) and so on.
Can I get/use this index number insted of the actual aelected value (by using: {post$['fig1']}, for example).
Because my forum is in Hebrew, I can't load images based on the Hebrew selection.


Ori...
So for example (taken from HTML Select Tag (W3Schools)):

<select name="myselect">
  <option value="volvo" selected="selected">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

If this is posted (and in MyBB), then you can use $mybb->input['myselect'], and it will return the result if POST is used (I think). If nothing is selected, then the default (volvo) will be used.
Sorry, but this doesn't work. I tried "{$post['$mybb->input['fid4']']}", with "$post['']" and without. 'fid4' is the custom field that holds the country names I use. And, btw, I don't want it to return the actual country name (that was, or wasn't, selected) - I want it to return the value's index number.
To explain: in the code you pasted, the option "volvo", should have an index of zero(0) and "saab", should have an index of one(1). This is something I know from programing (VB, C ...) - maybe it doesn't have this in PHP/HTML?

Ori...
If you're using $post, you can use $post['myselect'].

In my example, if I selected "Saab", then $post['myselect'] will equal "saab" (it's value in the select box). So it won't return the country, it will return the value.

If it doesn't work, then you're probably better off asking the question in the Plugins & Code Modifications section - this isn't really support for MyBB.

PHP/HTML can take numbers or letters in the value field, so yes - 0 and 1 are valid indexes in place of volvo and saab.