Jump to content

cleary1981

Members
  • Posts

    210
  • Joined

  • Last visited

Everything posted by cleary1981

  1. Need help cos my heads to sore to think. lol I want to set the height and width value from a database function generate_module() { //when generate button is pressed var h="50"; var w="50"; document.getElementById("object").src="box.gif"; document.getElementById("object").border=1; document.getElementById("object").height=h; document.getElementById("object").width=w; } </script>
  2. Hi All, I thought this was going to be easy but theres alot more involved than I thought. I can't find an example of what I want to do. I have a drop down box that when a value is selected it should find the appropriate description from my db and display it in a span with id= description. Heres the snippet of code from my html. <div id="leftSide"> <fieldset> <legend>Module</legend> <FORM name="drop_list"> <label for="type">Type</label> <div class="div_texbox"> <SELECT NAME="Category" onChange="SelectSubCat();" > <Option value="">Select Type</option> </SELECT> </div> <label for="mod_named">Model</label> <div class="div_texbox"> <SELECT id="model" NAME="SubCat" onChange="updateDesc();" > <Option value="">Select Model</option> </SELECT> </div> <fieldset> <legend>Description</legend> <span id="description">description goes here</description> </fieldset> <label for="mod_name">Name</label> <div class="div_texbox"> <input name="username" type="text" class="username" id="username" value="" /> </div> <div class="button_div"> <input name="Submit" type="button" value="Generate" class="buttons" /> </div> </form> </fieldset> </div> I know i need javascript for the updateDesc() and some php to query my db. Can anyone shed some light on this for a frustrated newbie?
  3. you wouldnt believe. <?php did the trick. :D
  4. Hi, I am trying to use php to populate 2 dropdown boxes both from a mysql db. Heres my main html code. <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>(Type a title for your page here)</title> <script language="javascript" src="list.php"></script> </head> <body> <FORM name="drop_list" action="" method="POST" > <SELECT NAME="Category" onChange="SelectSubCat();" > <Option value="">Category</option> </SELECT> <SELECT id="SubCat" NAME="SubCat"> <Option value="">SubCat</option> </SELECT> </form> </body> </html> and heres my php (list.php) <?php require "config.php"; // database connection details echo " function fillCategory(){ // this function is used to fill the category list on load "; $q1=mysql_query("select * from category"); echo mysql_error(); while($nt1=mysql_fetch_array($q1)){ echo "addOption(document.drop_list.Category, '$nt1[cat_id]', '$nt1[category]');"; }// end of while ?> } // end of JS function function SelectSubCat(){ // ON or after selection of category this function will work removeAllOptions(document.drop_list.SubCat); addOption(document.drop_list.SubCat, "", "SubCat", ""); // Collect all element of subcategory for various cat_id <? // let us collect all cat_id and then collect all subcategory for each cat_id $q2=mysql_query("select distinct(cat_id) from subcategory"); // In the above query you can collect cat_id from category table also. while($nt2=mysql_fetch_array($q2)){ //echo "$nt2[cat_id]"; echo "if(document.drop_list.Category.value == '$nt2[cat_id]'){"; $q3=mysql_query("select subcategory from subcategory where cat_id='$nt2[cat_id]'"); while($nt3=mysql_fetch_array($q3)){ echo "addOption(document.drop_list.SubCat,'$nt3[subcategory]', '$nt3[subcategory]');"; } // end of while loop echo "}"; // end of JS if condition } ?> } ////////////////// function removeAllOptions(selectbox) { var i; for(i=selectbox.options.length-1;i>=0;i--) { //selectbox.options.remove(i); selectbox.remove(i); } } function addOption(selectbox, value, text ) { var optn = document.createElement("OPTION"); optn.text = text; optn.value = value; selectbox.options.add(optn); } config is just the connection to my db. Im getting a syntax error but havnt a clue why.
  5. I have overwritten what i had with your new version. I still get the empty drop down box in the corner. My connection is definately working as I have used it in other pages.
  6. Hey sorry again I tried your code and it didnt work. I created a new table called ex_table with only the two fields ID and Name. Below is the code i used <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Simple Dymanic Drop Down</title> </head> <body> <!-- OK a basic form--> <form method="post" enctype="multipart/form-data" name="myForm" target="_self"> <table border="0"> <tr> <td> <select name="list1"> <option value=''></option> <?php //**(BELOW) CHANGE HOST, USERNAME AND PASSWORD $dbh = mysql_connect('localhost', 'admin', 'password') or die("Unable to connect to MySQL"); $selected = mysql_select_db("tes",$dbh) //<--**CHANGE DATABASE NAME (from first_test) if (!mysql_query("SELECT * FROM ex_table")) //<--**CHANGE TABLE NAME (from table) { echo "Database is down"; } while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { //**(Below update ID to the UniqueID or Name ALSO update the name (these are fields)) (from ID and Name) echo "<option value='".$row['ID']."'>".$row['Name']."</option>\n"; } mysql_close($dbh); ?> </select> </td> </tr> </table> <input type="submit" name="Submit" value="Submit" /> </form> </body> </html>
  7. Yeah I seen your example and im sure it works fine for those who understand it. Any chance you can write a simple example for us beginners. Im getting confused about where you have emulated the database and what i need to change
  8. Hi All, I have been trawling the net for a decent example of this but I can't find one. What I am looking for is an example (html, js and php files)of how to populate a dropdown box on page load with an item from a table in a mysql db where a description of the item selected is also displayed. i know this can be done but need a guru to show me the way without losing me.
×
×
  • 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.