Re: Re: Dynamic dropdown: where am I wrong?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 2011-05-24, at 11:55 PM, Karl DeSaulniers <karl@xxxxxxxxxxxxxxx> wrote:

> You could try using Ajax to get the field values from your database.
> And you wouldn't have to refresh the page.
> jQuery ajax does a nice job of this.
> 
> HTH,
> 
> Karl
> 
> On May 24, 2011, at 10:27 PM, Jim Giner wrote:
> 
>> not an expert but from some things that I've done...
>> When you handle the selection use JS and set a hidden field on your form
>> wiht the choice.  Do the same with your second dropdown and then let them
>> click on a 'submit' <input>
>> "Fahim Mohammad" <fahim.md@xxxxxxxxx> wrote in message
>> news:BANLkTim47cjrUsXYz=t-Yfhaoz_iUntesA@xxxxxxxxxxxxxxxxx
>>> Hi Php users,
>>> I have a form that has two (has more but for sake of brevity I am assuming
>>> it to be two) dropdown menu.
>>> 
>>> menu 1: select organism.
>>> 
>>> menu 2: select genome. This menu depends on the selected value in the
>>> first
>>> menu. It query into database and populate the result in this menu.
>>> 
>>> Once both are selected, I want a submit button that takes me to another
>>> page
>>> where I can process these values to perform some specific task on the
>>> database.
>>> 
>>> I am using the following form tag
>>> 
>>> <form name="theForm" method="get" enctype="multipart/form-data" action =
>>> 'processForm.php' >
>>> 
>>> I have the following problem now:
>>> 
>>> 1. If I keep the action value in the form tag above, after selecting the
>>> first option it direct me to the second page and I am not able to select
>>> the
>>> seconf option in the form.
>>> 
>>> 
>>> 2. If I remove the action value above then I can not submit the form as
>>> intended.
>>> 
>>> 3. If I remove the  "onChange="autoSubmit();"" from select tag then I am
>>> not
>>> able to pass the selected value in first option to mysql to get the
>>> result.
>>> 
>>> I think I reached a place from where it is not possible for me to proceed
>>> ahead. I may need to change something which I am not aware of.
>>> 
>>> Help needed.
>>> Thanks
>>> 
>>> [php]
>>> <?php
>>> include'login.php';
>>> $conn = mysql_connect($db_hostname, $db_username, $db_password );
>>> $db = mysql_select_db('rugit',$conn);
>>> if (!$db) die("Unable to connect to MySQL: " . mysql_error());
>>> ?>
>>> 
>>> <?php
>>> $organism = $genomeVer = null; //declare vars
>>> if(isset($_GET["organism"]) && is_string($_GET["organism"]))
>>> {
>>>   $organism = $_GET["organism"];
>>> }
>>> if(isset($_GET["genomeVer"]) && is_string($_GET["genomeVer"]))
>>> {
>>>   $genomeVer = $_GET["genomeVer"];
>>> }
>>> ?>
>>> 
>>> <script language="JavaScript">
>>> function autoSubmit()
>>> {
>>>   var formObject = document.forms['theForm'];
>>>   formObject.submit();
>>> }
>>> </script>
>>> 
>>> <!-- Form tag -->
>>> <form name="theForm" method="get" enctype="multipart/form-data"  >
>>> 
>>> <!-- Option 1: Select the organism -->
>>> <select name="organism" onChange="autoSubmit();">
>>>     <option value="null">Select Organism</option>
>>>     <option value= "human" <?php if(strcmp($organism, "human") == 0) echo
>>> " selected"; ?>>human</option>
>>>     <option value= "mouse" <?php if(strcmp($organism, "mouse") == 0) echo
>>> " selected"; ?>>mouse</option>
>>>     <option value= "rat" <?php if(strcmp($organism,"rat") == 0) echo "
>>> selected"; ?>>rat</option>
>>> </select> <br></br>
>>> 
>>> <!--Option 2: select the genome  -->
>>> <?php
>>>       //POPULATE DROP DOWN MENU FOR Genome version corresponding to a
>>> given organism
>>>      $sql = "SELECT genomeVer FROM organismGenomeVer WHERE organism =
>>> \"$organism\"";
>>>      $result = mysql_query($sql,$conn);
>>> ?>
>>>      <br>
>>>      <select name="genomeVer" onChange="autoSubmit();">
>>>      <option value="null">genomeVer</option>
>>> <?php
>>>      while($row = mysql_fetch_array($result))
>>>               {
>>>                echo ("<option value=\"$row[0]\" " . ($genomeVer ==
>>> $row["0"] ? " selected" : "") . ">$row[0]</option>");
>>>                 }
>>>               mysql_free_result($result);
>>>      echo"</select>";
>>> ?>
>>> <!-- Submit button -->
>>> <br></br>
>>> <input type="submit" value="submit" class="html-text-box">
>>> </form>
>>> 
>>> [/php]
>>> 
>>> 
>>> -- 
>>> Fahim
>>> 
>> 
>> 
>> 
>> -- 
>> PHP Database Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>> 
> 
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

Or cache the whole thing out to JS arrays and just load those. Do a search on linked dropdowns for sample code. Dynamicdrive.com is where i remember seeing some code and I would think that jQuery has something similar

Bastien
-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux