Jump to content

[SOLVED] How to SELECT item in lstbox?


A JM

Recommended Posts

If I have a listbox like so and I have a variable with the value of the item that I want to have selected how can this be done?

 

$selectedItem = $_GET['querytype'];

$selectBox = "<select id='querytype' name='querytype' onchange='loadWheres();'><option>Select Query Type</option>";
$selectBox = $selectBox.'<option value="number">Number</option>';
$selectBox = $selectBox.'<option value="name">Name</option>';
$selectBox = $selectBox.'<option value="address">Address</option>';
$selectBox = $selectBox.'<option value="state">State</option>';
$selectBox = $selectBox."</select>";



<script type="text/javascript">
function loadWheres() {
  var d = document.getElementById('querytype');
  var value = d.value;
  document.location = 'filtered_qrys.php?querytype=' + escape(value);
}
</script>

Link to comment
Share on other sites

I'm still trying to get this to work and having problems.

 

$selectBox = "<select id='querytype' name = 'querytype' onchange='loadWheres();'><option>Select Query Type</option>";
$selectBox = $selectBox."<option value=number<?php if(". $querytype ." == number) {echo selected=selected; }?>Number</option>";
$selectBox = $selectBox."</select>";

 

From the source of the page.

 

<select id='querytype' name = 'querytype' onchange='loadWheres();'><option>Select Query Type</option><option value=number <?php if(number == number) {echo selected=selected; }?>Number</option></select>

 

Since the php is showing on the page I know I have the syntax wrong...

 

Any help would be appreciated.

Link to comment
Share on other sites

$selectBox = "<select id='querytype' name = 'querytype' onchange='loadWheres();'><option>Select Query Type</option>";

$selectBox .= "<option value=number";

if ($querytype == "number") { $selectBox .= " selected=\"selected\""; }

$selectBox .= "?>Number</option>";

$selectBox .= "</select>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.