views:

173

answers:

1

I have two combo boxes, one for 'order by' and the other 'direction' (ascending, descending)

I am wondering what is the simplest way to have a default combination... e.g order by A-Z I would want ascending by default and order by views I would want descending by default.

I guess, onChange on the order combobox calling a JS function to set the value of the other combo box... but is there a simpler way?

Here are my comboboxes

<label>Order by:
<select name="o" id="o" onChange="menu.submit();">
    <option value="0" <?php if($_GET['o'] == 0) echo 'selected="selected"'; ?>>A - Z</option>
    <option value="1" <?php if($_GET['o'] == 1) echo 'selected="selected"'; ?>>Number of Views</option>
  </select>
  </label>
 <label>Direction:
  <select name="d" id="d" onChange="menu.submit();">
    <option value="0" <?php if($_GET['d'] == 0) echo 'selected="selected"'; ?>>Ascending</option>
    <option value="1" <?php if($_GET['d'] == 1) echo 'selected="selected"'; ?>>Descending</option>
  </select>
  </label>
A: 

Why not set the direction based on the order?:

<label>Order by:
 <select name="o" id="o" onChange="menu.submit();">
  <option value="0" <?php if($_GET['o'] == 0) echo 'selected="selected"'; ?>>A - Z</option>
  <option value="1" <?php if($_GET['o'] == 1) echo 'selected="selected"'; ?>>Number of Views</option>
 </select>
</label>
<label>Direction:
 <select name="d" id="d" onChange="menu.submit();">
  <option value="0" <?php if($_GET['o'] == 0) echo 'selected="selected"'; ?>>Ascending</option>
  <option value="1" <?php if($_GET['o'] == 1) echo 'selected="selected"'; ?>>Descending</option>
 </select>
</label>

Edit: LOL, nm you don't need the tenary operator to do the same thing. Oops, I think I hit the back button or something.. it made me double post.

And, yes you could use javascript to set a default option in the direction selector, but maybe it would be better to have a submit button instead? This gives the user more control over the selectors without causing a page reload.

fudgey