Jump to content

How can I disable php combobox's default option?


toasty

Recommended Posts

I'm in a bit of a quandary of this small snippet of code I'm trying to modify.  It's not my code, by the way :)  Anyway, this code works in a combo-box and here's the scenario that's giving me problems.

The default value in the box is simply text that outputs "[Archive]".  When a user selects one of the valid entries the page is correctly redirect to a dynamic php page with the URL populated by the unique ID of whatever their selection was.  However! - and this is the problem - if after making a selection, being redirected to the page the user clicks the back button in the browser taking them back to the page with the combo box; if they make the selection of the "[Archive]" value, they are then redirected to a page (as specified in the code) but with a "blank" ID in the URL.

All I want to do is make it so that if the user does click "back" and (un)intentionally selects "[Archive]" they're not redirected [B]anywhere[/B].

Here's the code that's at work (as far as I can tell):
[code]
<?php
class ccm_archive {
var $DB_PREFIX;

var $_db;
var $_config;
var $_common;

function ccm_archive($db,$dbConfig,$config,$common) {
$this->_db = $db;
$this->DB_PREFIX = &$dbConfig->prefix;

$this->_config = &$config;
$this->_common = $common;
}

function listComicsSelectBox($showIDs='', $reverse='', $storylines='') {
$order = (empty($reverse)) ? 'ASC' : 'DESC';

$result = $this->_db->Execute("SELECT id,date,comic_title,storyline
FROM {$this->DB_PREFIX}comic
WHERE live='1' ORDER BY date $order");

$r = '<select name="comicID" onchange="location.href=\''
.$this->_config->archive_comic_url."?comicID='+value;\">";
$r .= '<option value="">[Archives]</option>';

while (!$result->EOF) {
list ($id,$date,$title,$sl) = $result->fields;

$indent = (!empty($storylines) && (!empty($sl))) ? '&nbsp;&nbsp;' : '';
$r .= "<option value=\"$id\">";
$r .= (empty($showIDs)) ? "$indent $title" : "$indent [$id] $title";
$r .= "</option>";

$result->MoveNext();
}

$r .= '</select>';
return $r;
}
}
$ccm_archive = new ccm_archive(&$ccm_db,&$ccm_dbConfig,&$ccm_config,&$ccm_common);
?>[/code]

The combo box itself is called onto the page with a very simple PHP code specifying the listComicSelectBox function.

Thanks for your help everyone!
[quote author=HuggieBear link=topic=124299.msg515362#msg515362 date=1169988699]
Do you have this code live anywhere, so we can see what you mean?

Regards
Huggie
[/quote]

I definitely realize the benefit of having a place I can showcase the issue at hand.  Right now it's in a testing location and I've been sworn to secrecy :P  However, I was able to get the code I was looking for to fix the issue at hand.

Replacing:[code]
$r = '<select name="comicID" onchange="location.href=\''
.$this->_config->archive_comic_url."?comicID='+value;\">";[/code]
with:[code]
$r = '<select name="comicID" onchange="if(this.value != \'\')
location.href=\''
.$this->_config->archive_comic_url."?comicID='+value;\">";[/code]

That did the trick :)

Thanks for taking an interest in my plea for help Huggie, I definitely appreciate it. :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.