PHP - Php & Mysql - Dropdowns With Onchange
Good day, I new to PHP I am having problems with a two dropdowns on a form, can someone please tell me where I'm going wrong.
[attachment deleted by admin] Similar TutorialsI have two drop down menus in a table side by side being populated exactly the same from a msql database. The first menu populates fine but the second one is blank. They are both supposed to be identical, the same info from the same table so I assume that's my problem. I tried moving the while loop so it encapsulates both drop downs but then it messes up the table structure. I tried changing the name of some of the variables by adding "2" on the end & that didn't work either. Is it because once a while loop is executed it can't be used again on the same instance? Heres my code so far: <tr> <td > <select name="wall_type" size="1" style="width: 175px;" > <?php while ($walls_row=mysql_fetch_array($result_walls)) { $type_name=$walls_row["type"]; $type_id=$walls_row["id"]; ?> <option value="<?php echo $type_id; ?>"><?php echo $type_name; ?> </option> <?php } ?> </select> </td> <td > <select name="wall_type2" size="1" style="width: 175px;"> <?php while ($walls_row2=mysql_fetch_array($result_walls)) { $type_name2=$walls_row2["type"]; $type_id2=$walls_row2["id"]; ?> <option value="<?php echo $type_id2; ?>"><?php echo $type_name2; ?> </option> <?php } ?> </select> </td> </tr> Hi everyone. I have a combo box which lists usernames and onchange, the username value is passed to a textbox. however, I have 3 textboxes i need to populate based on the selection of the combobox: username. department and email. i have the username going into a textbox, but i'm not sure how to pass department and email into two other textboxes. I'd appreciate any help you could provide. Thanks. Code: [Select] <script> function CBtoTB() {document.getElementById("username").value=document.getElementById("usernameselect").value} </script> <?php $result=mysql_query("select Username, EMail, Department from users"); $options=""; while ($row=mysql_fetch_array($result)) { $username=$row["Username"]; $options.="<OPTION VALUE=\"$username\">".$username.'</option>'; } ?> <select name="usernameselect" id="usernameselect" onchange="CBtoTB()"> <option value="">< select user ><?php echo $options ?></option> </select> <input name="username" type="text" id="username" value="<?php echo $username ?>" size="25" readonly="readonly" /> hi everyone i have a question i tought was easy but im having some problems i have 3 dropdowns menus the customer select one category from one of them.. let say "pets" the the other dropdown must be filled with pets (dogs, cats, parrots...) if the customer select dogs the 3rd dropdown must filled with (doberman, bulldog,chihuhaua, etc) i think u got the idea.. but im having trouble with the 2nd and 3rd dropdown... any ideas::: tnx in advncd Hello to all!
I have a question. I really like that kind of button http://getbootstrap....dropdowns-split
I tried it without JS and it doen't work...
Is there a way, for user without JS to make it works?
Thanks a lot!
Pascal
I need some serious help filtering search results using dropdown boxes. Right now my search is working perfectly fine. It searches by the keywords that people enter in and returns the results. My only problem is that after getting those results, I want people to be able to filter those results using dropdown boxes. So if someone searches by the keyword artwork, it will pull up all of my portfolio images that have artwork as a keyword. Now if they want to filter those results by: Color: Green, Type: Painting and Size: Large then they can use the dropdown boxes that will be populated with that information based off of their search term. I have no idea on how to even get started on something like this, so I would really appreciate all of the help I can get. Thanks in advance! If I have a variable and a hard coded select dropdown, what is the easiest way to compare the variable with the value and set that particular option's selected attributed to selected? Hello, I have a drop down box that filters my table data by City and displays the results. It works! Now I am trying to add a second drop down menu to filter by name. When name is selected AND city is selected, the display should be the same names that live in the same city. Can anyone ties these 2 drop downs together for me? Here is my table: Code: [Select] CREATE TABLE IF NOT EXISTS `data` ( `id` int(11) NOT NULL auto_increment, `from_date` date NOT NULL, `to_date` date NOT NULL, `full_name` varchar(250) NOT NULL, `email` varchar(250) NOT NULL, `city` varchar(250) NOT NULL, PRIMARY KEY (`id`) ) And here is the html and PHP in one file: Code: [Select] <?php error_reporting(0); include("config.php"); ?> <!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=utf-8" /> <title>MySQL table search</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> <style> BODY, TD { font-family:Arial, Helvetica, sans-serif; font-size:12px; } </style> </head> <body> <form id="form1" name="form1" method="post" action="search.php"> <label>Name</label> <select name="name"> <option value="">--</option> <?php $sql = "SELECT * FROM ".$SETTINGS["data_table"]." GROUP BY full_name ORDER BY full_name"; $sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql); while ($row = mysql_fetch_assoc($sql_result)) { echo "<option value='".$row["full_name"]."'".($row["full_name"]==$_REQUEST["full_name"] ? " selected" : "").">".$row["full_name"]."</option>"; } ?> </select> <label>City</label> <select name="city"> <option value="">--</option> <?php $sql = "SELECT * FROM ".$SETTINGS["data_table"]." GROUP BY city ORDER BY city"; $sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql); while ($row = mysql_fetch_assoc($sql_result)) { echo "<option value='".$row["city"]."'".($row["city"]==$_REQUEST["city"] ? " selected" : "").">".$row["city"]."</option>"; } ?> </select> <input type="submit" name="button" id="button" value="Filter" /> </label> <a href="search.php"> reset</a> </form> <br /><br /> <table width="700" border="1" cellspacing="0" cellpadding="4"> <tr> <td width="90" bgcolor="#CCCCCC"><strong>From date</strong></td> <td width="95" bgcolor="#CCCCCC"><strong>To date</strong></td> <td width="159" bgcolor="#CCCCCC"><strong>Name</strong></td> <td width="191" bgcolor="#CCCCCC"><strong>Email</strong></td> <td width="113" bgcolor="#CCCCCC"><strong>City</strong></td> </tr> <?php if ($_REQUEST["city"]<>'') { $search_city = " AND city='".mysql_real_escape_string($_REQUEST["city"])."'"; } if ($_REQUEST["from"]<>'' and $_REQUEST["to"]<>'') { $sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE from_date >= '".mysql_real_escape_string($_REQUEST["from"])."' AND to_date <= '".mysql_real_escape_string($_REQUEST["to"])."'".$search_string.$search_city; } else if ($_REQUEST["from"]<>'') { $sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE from_date >= '".mysql_real_escape_string($_REQUEST["from"])."'".$search_string.$search_city; } else if ($_REQUEST["to"]<>'') { $sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE to_date <= '".mysql_real_escape_string($_REQUEST["to"])."'".$search_string.$search_city; } else { $sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE id>0".$search_string.$search_city; } $sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql); if (mysql_num_rows($sql_result)>0) { while ($row = mysql_fetch_assoc($sql_result)) { ?> <tr> <td><?php echo $row["from_date"]; ?></td> <td><?php echo $row["to_date"]; ?></td> <td><?php echo $row["full_name"]; ?></td> <td><?php echo $row["email"]; ?></td> <td><?php echo $row["city"]; ?></td> </tr> <?php } } else { ?> <tr><td colspan="5">No results found.</td> <?php } ?> </table> </body> </html> Hello, any help would be greatly appreciated. I have two dropdowns with 2 options in each. Customer picks one option from each dropdown and the form gets emailed to addresses from the two selections. The code below gives and error. My form: <form method="POST" action="quote.php" onsubmit="return checkform(this)"> <input type="hidden" name="agent" value="recipient_1,recipient_2"> <input type="hidden" name="office" value="recipient_3,recipient_4"> <select name="agent" id="agent"> <option value="recipient_1">Agent1 </option> <option value="recipient_2">Agent2 </option> </select> <select name="office" id="office"> <option value="recipient_3">Location1 </option> <option value="recipient_4">Location2 </option> </select> <input type="submit" name="submit" value="Submit"> </form> quote.php is below: $recipients = array( 'recipient_1' => 'email_1@yahoo.com', 'recipient_2' => 'email_2@yahoo.com', 'recipient_3' => 'email_3@yahoo.com', 'recipient_4' => 'email_4@yahoo.com', ); $exploded_recipients = explode(",",$_REQUEST['agent']); foreach($exploded_recipients as $value) { $my_email = $recipients[$value]; $success = mail($my_email, $Subject, $Body, "From: <$EmailFrom>"); } Thanks in advance for starters, i am a complete beginner at PHP, so i know almost nothing.
so, the basic outline is that i am required to create a table with 2 columns, and use PHP where i can
so the first set of code lays down the table and the ability to type in text of "name" and "surname". ----i think this "input" is HTML, yes?? is there a way to enter it as PHP?
<table border=\"2\"> <tr><th><b>Requirements</b></th><th><b>Selections</b></th></tr> <tr><td>Name</td><td><input type="text" name="name"/></td></tr> <tr><td>Surname</td><td><input type="text" name="surname"/></td></tr>so, for this next section, adding on is the part for "age". i want this to appear as a dropdown selection. i've written PHP where possible, however this does not work when opening the file in a browser. it simply leaves a blank dropdown menu with no options. ???? <tr><td>Age</td><td><select> <?php for ($num=11; $num<=22; $num++){ echo '<option>' .$num. '</option>'; } ?> </select>lastly, i have the part for "activity choice". this again i believe i wrote the radio buttons in HTML??? am i able to write this as PHP???? <tr><td>Activity Choice</td><td><input type="radio" name="activityChoice" value "music"/> Music ($30.00)<br> <input type="radio" name="activityChoice" value "swimming"/> Swimming ($25.50)<br> <input type="radio" name="activityChoice" value "tennis"/> Tennis ($20.00)<br> <input type="radio" name="activityChoice" value "basketball"/> Basketball ($15.50)<br> <input type="radio" name="activityChoice" value "netball"/> Netball ($15.50)<br> <input type="radio" name="activityChoice" value "dance"/> Dance ($10.50)<br> <input type="radio" name="activityChoice" value "communityService"/> Community Service (No Charge)</td></tr> This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=320136.0 Hi, I need to develop a code that allows me to choose how I want to see a list of data from the database. For example, I could choose to see "the most recent first" or "most recent last". I have this example on how work the "onChange" event: <html> <head> <title>Select Example</title> <script> function onSelectChange(){ var dropdown = document.getElementById("developer"); var index = dropdown.selectedIndex; var ddVal = dropdown.options[index].value; var ddText = dropdown.options[index].text; if(ddVal != 0) { output = "You Selected " + ddText; } document.getElementById("output").innerHTML = output; } </script> </head> <body> <h3>Developers</h3> <select id="developer" onChange="onSelectChange();"> <option value="0">the most recent first</option> <option value="1">the most recent flast</option> </select> <br / <div id="output"></div> </body> </html> Now I need to apply this to a SELECT from the database that will use this method to list data. I have tried to google it, but I can't find any example. Can someone give me a clue on how to find the way of doing this? Best Regards, This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=305968.0 Ok so i want to grab an id from the checkbox then grab the option drop down associated with that check box and update a mysql row here is my code so far any help is awesome help taaaanks guys <?php mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("db1") or die(mysql_error()); $query = "SELECT * FROM tickets ORDER BY id DESC"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { print "<input name='delete[]' value='{$row['id']}' type='checkbox'>"; mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("db1") or die(mysql_error()); $query2 = "SELECT * FROM admin"; $result2 = mysql_query($query2) or die(mysql_error()); print "<form name='namestoupdate' method='post' action='update.php'>\n"; print '<select>'; while($row2 = mysql_fetch_array($result2)) { if ($row2['priv']==prov){print '<option value="'.$row2['user'].'" name="prov['.$i++.']">'.$row2['user'].'</option>';} } print '</select>'; print "<input type='submit' value='submit' />"; print "</form>"; } ?> Visual aid This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=330989.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=333787.0 Hey guys I wasnt sure if this is a php topic or java script im trying to make my drop down menu's activate onchange. what confuses me is how do I make php know that the java script is being run. Or have the java script trip my php code. To know a button has been pressed i use "if (isset['_POST'])" echo '<select name="siege_list" id="siege_list">'; foreach($name as $key => $value) { echo '<option value="' . $value['name'] . '" ' . ($value['name'] == $current1 ['name'] ? 'selected="selected"' : '') . '> ' . $value['name'] . '</options>'; } echo '</select><input type="submit" id="siege_planet" onchange="this.form.submit()">'; Hello: I have a SELECT dropdown menu that works like this: Code: [Select] <?php $states_arr = array('AL'=>"Alabama",'AK'=>"Alaska",'AZ'=>"Arizona",'AR'=>"Arkansas",'CA'=>"California",'CO'=>"Colorado",'CT'=>"Connecticut",'DE'=>"Delaware",'DC'=>"District Of Columbia",'FL'=>"Florida",'GA'=>"Georgia",'HI'=>"Hawaii",'ID'=>"Idaho",'IL'=>"Illinois", 'IN'=>"Indiana", 'IA'=>"Iowa", 'KS'=>"Kansas",'KY'=>"Kentucky",'LA'=>"Louisiana",'ME'=>"Maine",'MD'=>"Maryland", 'MA'=>"Massachusetts",'MI'=>"Michigan",'MN'=>"Minnesota",'MS'=>"Mississippi",'MO'=>"Missouri",'MT'=>"Montana",'NE'=>"Nebraska",'NV'=>"Nevada",'NH'=>"New Hampshire",'NJ'=>"New Jersey",'NM'=>"New Mexico",'NY'=>"New York",'NC'=>"North Carolina",'ND'=>"North Dakota",'OH'=>"Ohio",'OK'=>"Oklahoma", 'OR'=>"Oregon",'PA'=>"Pennsylvania",'RI'=>"Rhode Island",'SC'=>"South Carolina",'SD'=>"South Dakota",'TN'=>"Tennessee",'TX'=>"Texas",'UT'=>"Utah",'VT'=>"Vermont",'VA'=>"Virginia",'WA'=>"Washington",'WV'=>"West Virginia",'WI'=>"Wisconsin",'WY'=>"Wyoming"); function showOptionsDrop($array){ $string = ''; foreach($array as $k => $v){ $string .= '<option value="'.$k.'"'.$s.'>'.$v.'</option>'."\n"; } return $string; } ?> <form> <select name="states"> <option value="0">Choose a state</option> <?php echo showOptionsDrop($states_arr); ?> </select> </form> I would like to show all the towns/zipcodes for each individual state with an "onchange" from the SELECT menu. The table is called "zip_codes" and the City/Zip Codes are called "city" and "zip" What I would like to do is display them as links, so a user can click into each town and either create a new entry (a restaurant) or update an existing entry. What would be the best approach for this? I appreciate the help. How can I make my on change in the form pass through the year thats been selected, then use that in the second query? Code: [Select] <select name="mySelect" onchange=""> <?php $result= mysql_query('SELECT DISTINCT Year FROM MonthlySales'); ?> <?php while($row= mysql_fetch_assoc($result)) { ?> <option value="<?php echo htmlspecialchars($row['Year']);?>"> <?php echo htmlspecialchars($row['Year']); ?> </option> <?php } ?> </select> <?php $query="SELECT * FROM MonthlySales WHERE Year = PASS YEAR SELECTED VARIABLE TO THIS BIT HERE"; $results = mysql_query ( $query, $conn); Hey phpFreaks, im having some troubles getting my script to work correctly and im also not sure if this issue is in the right section of the forum. but heres what i have going on. I have a query result that displays a list of images with a checkbox and a couple buttons for edit and delete. everything works fine other than the checkbox stuff. I had it working when i was using a submit button, but i wanted to get rid of that button cuz it was only dealing with the checkboxes. so whats going on when using the checkboxes is that when checked or uncheck it would submit the form. It works to submit but its not submitting any data to the database. heres what i got for code for this section of checkbox. Code: [Select] <?php echo '<form method="post">'; if(isset($_POST['submit'])){ foreach($_POST['id'] as $id){ $value = (isset($_POST['location'][$id]) && $_POST['location'][$id]=="0" ? '0' : '1'); $insert = mysql_query("UPDATE items SET location='$value' WHERE id='$id'") or die('Insert Error: '.mysql_error()); } } $result = mysql_query("SELECT * FROM items") or die("Query Failed: ".mysql_error()); $counter = 0; echo '<div class="specialcontainer">'; while($row = mysql_fetch_array($result)){ list($id, $item_info, $item_img, $price, $sale, $location) = $row; if($location == '0'){ $set_checked = 'checked="checked"'; }else{ $set_checked = ''; } if($counter % 5==0) { echo '</div>'; echo '<div class="specialcontainer">'; } echo '<div class="special"><img src="../images/items/'.$item_img.'" width="130" /><br />'.$item_info.'<br />$'.$price.'<br />$'.$sale.'<br />Slide Show: <input type="checkbox" id='.$id.' value="0" name="location['.$id.']" '.$set_checked.' onchange="this.form.submit()"/><br /><input type="button" value="Edit" name="edit" id="'.$id.'" onclick="window.location.href=\'specials.php?action=edit&id='.$id.'\'"><input type="button" value="Delete" name="Delete" id="'.$id.'" onclick="window.location.href=\'specials.php?action=delete&id='.$id.'\'"><input type="hidden" name="id[]" value='.$id.' /></div>'; $counter++; } echo '</div>'; echo '</form>'; ?> Hi there, I am having a PHP form with simple combo box. Here is the code: <form name="form1" method="get" action=""> <select name="select" onChange="form1.submit()"> <option value='value1'>My Value1</option> <option value='value2'>My Value2</option> <option value='value3'>My Value3</option> </select> </form> Now the form is successfully being submitted upon 'onChange' event. The only thing I am trying to do is to retain the value of the new option. As every time I select the value from the combo, it goes back and displays the 'value 1' even when I select value 3 or 2. How do I make the combo box retain the value as 3 (when I select option 3) after the form is submitted. Please reply. Thank you! |