Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2006
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How can I disable php combobox's default option?

    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):
    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);
    ?>
    The combo box itself is called onto the page with a very simple PHP code specifying the listComicSelectBox function.

    Thanks for your help everyone!

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Change
    PHP Code:
    $r '<select name="comicID" onchange="location.href=\''
                    
    .$this->_config->archive_comic_url."?comicID='+value;\">"
    to
    PHP Code:
    $r '<select name="comicID" onchange="if(this.value != \'\') location.href=\''
                    
    .$this->_config->archive_comic_url."?comicID='+value;\">"
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Oct 2006
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    Change
    PHP Code:
    $r '<select name="comicID" onchange="location.href=\''
                    
    .$this->_config->archive_comic_url."?comicID='+value;\">"
    to
    PHP Code:
    $r '<select name="comicID" onchange="if(this.value != \'\') location.href=\''
                    
    .$this->_config->archive_comic_url."?comicID='+value;\">"
    Woo Hoo!!

    Worked like a champ, thank you Soooo much!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •