...

View Full Version : How can I disable php combobox's default option?



toasty
01-27-2007, 04:04 PM
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 anywhere.

Here's the code that's at work (as far as I can tell):


<?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);
?>

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

Thanks for your help everyone!

_Aerospace_Eng_
01-27-2007, 04:51 PM
Change

$r = '<select name="comicID" onchange="location.href=\''
.$this->_config->archive_comic_url."?comicID='+value;\">";
to

$r = '<select name="comicID" onchange="if(this.value != \'\') location.href=\''
.$this->_config->archive_comic_url."?comicID='+value;\">";

toasty
01-27-2007, 04:56 PM
Change

$r = '<select name="comicID" onchange="location.href=\''
.$this->_config->archive_comic_url."?comicID='+value;\">";
to

$r = '<select name="comicID" onchange="if(this.value != \'\') location.href=\''
.$this->_config->archive_comic_url."?comicID='+value;\">";

:eek: Woo Hoo!!

Worked like a champ, thank you Soooo much!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum