Web Analytics Made Easy -
StatCounter dropdown submit more then one value.. - CodingForum

Announcement

Collapse
No announcement yet.

dropdown submit more then one value..

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • dropdown submit more then one value..

    Hey right now my dropdown only submits one value but i also want it to submit a blank value for the next one as well which is the productCat_id drop down...


    Code:
    <select name="industry_id" id="center" onchange="document.distributers.value='industry_id';document.distributers.submit();"

    how would i change that line to make that work?

  • #2
    Encapsulate in a form.

    To pass along an additional blank value two things must happen.

    1. a second input element to contain the blank value and name must exist.

    2. Both the select element and the additional element must be contained within the same form.

    Then, you just submit the form that contians both values.
    Since you wanted to pass along a blank value that should not be user changeable I used a hidden input element as the additional input element.
    PHP Code:
    <html>
        <
    head>
            <
    title>Hidden form element</title>
        </
    head>
        <
    body>
            <
    form name="distributers" id="distributers">
                
    Industry:
                <
    select name="industry_id" id="center" onchange="distributers.submit();">
                    <
    option value="NA" selected="selected">Select an industry.</option>
                    <
    option value="IT">InfoTech.</option>
                    <
    option value="CS">CustService</option>
                </
    select>
                <
    input type="hidden" value="" name="productCat_id" id="productCat_id">
            </
    form>
        </
    body>
    </
    html
    Give us more of your code and we can help better.

    Comment


    • #3
      Code:
         <select name="industry_id" id="center" onchange="document.distributers.submit();">
      				
      			      <option value="">Select an Industry...</option>
      			      <?php do { ?>
      			     <?php
         					 print "<option value=\"{$row_rs_industry['industry_id']}\"" .
          				(isset($_GET['industry_id']) && $_GET['industry_id'] == $row_rs_industry['industry_id'] ? " selected>" : ">") . 
         					 "{$row_rs_industry['industry_name']}</option>\n";?>	
      					      
      			      <?php } while ($row_rs_industry = mysql_fetch_assoc($rs_industry)); ?>
      		        </select> <input type="hidden" value="" name="productCat_id" id="productCat_id"> 		</td></tr>
      				 <tr><td>Product category:</td><td>
      				 
      				 <?php if ($_GET['industry_id'] == null || $_GET['industry_id'] == "") { ?>
      				 <select name="productCat_id" onchange="document.distributers.submit();" disabled>;
      				 <?php } else { 
      					mysql_select_db($database_conn_dj, $conn_dj);
      					$query_rs_productcategory = "SELECT productCat_id, productCat_name, industry_id FROM tbl_productcat WHERE industry_id = '$_GET[industry_id]' ORDER BY productCat_name";
      					$rs_productcategory = mysql_query($query_rs_productcategory, $conn_dj) or die(mysql_error());
      					$row_rs_productcategory = mysql_fetch_assoc($rs_productcategory);
      					$totalRows_rs_productcategory = mysql_num_rows($rs_productcategory);
      				 ?>			 
      			<select name="productCat_id" onchange="document.distributers.submit();" >
      			      <option value="">Select a product category...</option>
      				<?php do {
         					 print "<option value=\"{$row_rs_productcategory['productCat_id']}\"" .
          				(isset($_GET['productCat_id']) && $_GET['productCat_id'] == $row_rs_productcategory['productCat_id'] ? " selected>" : ">") . 
         					 "{$row_rs_productcategory['productCat_name']}</option>\n";
      			     } while ($row_rs_productcategory = mysql_fetch_assoc($rs_productcategory)); ?>
      		        </select>
      		 		<?php } ?></td>
      				
      				<tr><td>Product:</td><td>
      					
      				 <?php if ($_GET['productCat_id'] == null || $_GET['productCat_id'] == "" || ($_GET['industry_id'] == null || $_GET['industry_id'] == "")) { ?>
      				 <select name="products_id" onchange="document.distributers.submit();" disabled>;
      				 <?php } else { 	
      					mysql_select_db($database_conn_dj, $conn_dj);
      					$query_rs_product = "SELECT products_id, products_name, productCat_id FROM tbl_products WHERE productCat_id = '$_GET[productCat_id]' ORDER BY products_name";
      					$rs_product = mysql_query($query_rs_product, $conn_dj) or die(mysql_error());
      					$row_rs_product = mysql_fetch_assoc($rs_product);
      					$totalRows_rs_product = mysql_num_rows($rs_product);
      					?>		 
      			<select name="products_id" id="center" onchange="document.distributers.submit();" >
      			      <option value="">Select a product...</option>
      					<?php do {
      	   					 print "<option value=\"{$row_rs_product['products_id']}\"" .
      	    				(isset($_GET['products_id']) && $_GET['products_id'] == $row_rs_product['products_id'] ? " selected>" : ">") . 
      	   					 "{$row_rs_product['products_name']}</option>\n";
      				     } while ($row_rs_product = mysql_fetch_assoc($rs_product)); ?>
      			        </select>
      				<?php } ?> 	
      								</td></tr>
      			    <tr><td>&nbsp;</td><td><input type="submit" value="Find" name="find"></td></tr>
                </table>
      		    </form>
      ok here is the entire thing i'm one step away now it is submitting that value but what i would like is it to override the url with that value like say the user selects the industry and the productCat_id and then a product_id and decides they want a differnt industry when they click a new industry i want it to send just industry_id and a blank rest of the url if possible...

      Comment


      • #4
        Client Side query handling.

        Ok... Try this out... does this work the way you want your page to work?

        PHP Code:
        <html>
            <
        head>
                <
        title>Client side query handling.</title>
                <
        script type="text/javascript">
                var 
        industries,ind,cat,prod;
                
                function 
        Industry(id,txt,cat) {
                    
        this.id id;
                    
        this.text txt;
                    
        this.category cat;
                }
                
                function 
        Category(id,txt,prod){
                    
        this.id id;
                    
        this.text txt;
                    
        this.products prod;
                }
                
                function 
        Product(id,txt){
                    
        this.id id;
                    
        this.text txt;
                }
                
                function 
        getProdArray(){
                    var 
        arguments.length;
                    var 
        arr = new Array();
                    for (var 
        0li+=2){
                        
        arr[arr.length] = new Product(arguments[i],arguments[i+1]);
                    }
                    return 
        arr;
                }
                
                function 
        getCatArray(){
                    var 
        arguments.length;
                    var 
        arr = new Array();
                    for (var 
        0li+=3){
                        
        arr[arr.length] = new Category(arguments[i],arguments[i+1],arguments[i+2]);
                    }
                    return 
        arr;
                }

                function 
        getIndArray(){
                    var 
        arguments.length;
                    var 
        arr = new Array();
                    for (var 
        0li+=3){
                        
        arr[arr.length] = new Industry(arguments[i],arguments[i+1],arguments[i+2]);
                    }
                    return 
        arr;
                }
                
                
        //Here we build the database.
                
        function initData(){
                    
        industries getIndArray// use CGI to generate these contents
                        
        "IT""Info. Tech."getCatArray(
                            
        "SFT","Software"getProdArray"NW""Net Watcher""SS""System Scanner""FW""Fire Wall" ),
                            
        "SRV","Services"getProdArray"SA""Security Analysis""SEO""Search Engine Optimization" )
                        ),
                        
        "CS""Cust. Service"getCatArray(
                            
        "PER""Live Assistance"getProdArray"TS""Technical Support Hotline""DC""Debt Collection" ),
                            
        "DIG""Automated Responce"getProdArray"BA""Billing / Account Info Database""OL""Online Account Management" )
                        )    
                    );
                    
        // Note: you don't have to supply all the data at one time.  If the user can't select products, you can replace "getProdArray(...)" with "null".
                
        }
                
                function 
        processQuery() {
                    var 
        location.search;
                    
        q.substr(q.indexOf('?')+1);
                    
        q.split('&');
                    var 
        q.length;
                    for( var 
        0li++) {
                        
        q[i] = q[i].split('=');
                        if (
        q[i][1] == ''q[i][1] == null;
                        if (
        q[i][0].match(/industry_id/i))ind=q[i][1];
                        if (
        q[i][0].match(/productCat_id/i))cat=q[i][1];
                        if (
        q[i][0].match(/product_id/i))prod=q[i][1];
                    }
                    if (
        typeof(ind) == "string"){
                        for (var 
        0industries.lengthi++){
                            if (
        ind == industries[i].id){
                                
        ind=i;
                                for (var 
        0industries[ind].category.lengthj++){
                                    if (
        cat == industries[ind].category[j].id){
                                        
        cat=j;
                                        for (var 
        0industries[ind].category[cat].products.lengthk++){
                                            if(
        prod == industries[ind].category[cat].products[k].id){
                                                
        prod k;
                                                break;
                                            }
                                        }
                                        break;
                                    }
                                }
                                break;
                            }
                        }
                    }
                }

                
        initData();
                
        processQuery();
                </
        script>
            </
        head>
            <
        body>
                <
        form name="distributers" id="distributers">
                    
        Industry:
                    <
        select name="industry_id" id="industry_id" onchange="distributers.submit();">
                        <
        option value="">Select an industry</option>
                        <
        script type="text/javascript">
                            for(var 
        0industries.lengthi++){
                                
        document.write('<option value="'+industries[i].id+'">');
                                
        document.write(industries[i].text+"</option>");
                            }
                            if(
        typeof(ind)=="number")distributers.industry_id.selectedIndex=ind+1;
                        </
        script>
                    </
        select><br>
                    
        Category:
                    <
        select name="productCat_id" id="productCat_id" onchange="distributers.submit();" disabled="disabled" >
                    <
        option value="">Select a category</option>
                        <
        script type="text/javascript">
                            if(
        typeof(ind)=="number"){
                                for(var 
        0industries[ind].category.lengthi++){
                                    
        document.write('<option value="'+industries[ind].category[i].id+'">');
                                    
        document.write(industries[ind].category[i].text+"</option>");
                                }
                                if(
        typeof(cat)=="number")distributers.productCat_id.selectedIndex=cat+1;
                                
        distributers.productCat_id.disabled="";
                            }
                        </
        script>
                    </
        select><br>
                    
        Product:
                    <
        select name="product_id" id="product_id" onchange="distributers.submit();" disabled="disabled">
                    <
        option value="">Select a product</option>
                        <
        script type="text/javascript">
                            if((
        typeof(ind)=="number")&&(typeof(cat)=="number")){
                                for(var 
        0industries[ind].category[cat].products.lengthi++){
                                    
        document.write('<option value="'+industries[ind].category[cat].products[i].id+'">');
                                    
        document.write(industries[ind].category[cat].products[i].text+"</option>");
                                }
                                if(
        typeof(prod)=="number"){
                                    
        distributers.product_id.selectedIndex=prod+1;
                                }
                                
        distributers.product_id.disabled="";
                            }
                        </
        script>
                    </
        select>
                </
        form>
                <
        hr>
                <
        script type="text/javascript">
                    if((
        typeof(ind)=="number")&&(typeof(cat)=="number")&&(typeof(prod)=="number")){
                        
        document.write("<h1>You have made your selection:</h1>"+industries[ind].text+" &gt; "+industries[ind].category[cat].text+" > "+industries[ind].category[cat].products[prod].text);
                        
        document.write(
                            
        '<br><button onclick="location=\'http://www.vortexcortex.com/buy.cgi?industry_id='+
                            
        industries[ind].id+
                            
        '&productCat_id='+
                            
        industries[ind].category[cat].id+
                            
        '&product_id='+
                            
        industries[ind].category[cat].products[prod].id+
                            
        '\'">Continue to Pricing Page</button>'
                        
        )
                    }
                </
        script>
            </
        body>
        </
        html
        If it works the way you want, then we can adapt it to work with your PHP.

        Note: the above code can also be modified so that the page only loads once which would reduce server load.
        Last edited by VortexCortex; Oct 5, 2006, 03:21 PM. Reason: Squashed a bug.

        Comment

        Working...
        X