PHP - Help: Changing Drop Down Values According To Selection
I am trying to make a Web Form for people to fill out that has two drop down menus where i want the first drop down menu's selection changes the values of the selections in the second drop down. ((IE. If the first drop down value is "product 01" then the second drop down shows values "Red, Green, Blue" while if the first drop down value is "product 02" then the second drop down shows values "Yellow, Green"))
Anyone have any ideas? Thanks in Advance. Similar TutorialsHi All, I have 2 tables: one CarMake - CarMakeID - CarMakeDesc two CarModel - CarModelID - CarModelMake - CarModelDesc Depending on what the user selects in the first dropdown (carmake) the possible selection in the second dropdown (model) needs to be limited to only the models from the selected carmake. in the second table (Carmodel : the 'CarModelMake' = CarMakeID, to identify the make) How do I limit the dropdown 'CarModel' based on the selected CarMake in the first dropdown. link : http://98.131.37.90/postCar.php code : -- -- -- Code: [Select] <label> <select name="carmake" id="CarMake" class="validate[required]" style="width: 200px;"> <option value="">Select CAR MAKE...</option> <?php while($obj_queryCarMake = mysql_fetch_object($result_queryCarMake)) { ?> <option value="<?php echo $obj_queryCarMake->CarMakeID;?>" <?php if($obj_queryCarMake->CarMakeID == $CarAdCarMake) { echo 'selected="selected"'; } ?> > <?php echo $obj_queryCarMake->CarMakeDesc;?></option> <?php } ?> </select> </label> <label> <select name="carmodel" id="CarModel" class="validate[required]" style="width: 200px;"> <option value="">Select MODEL...</option> <?php while($obj_queryCarModel = mysql_fetch_object($result_queryCarModel)) { ?> <option value="<?php echo $obj_queryCarModel->CarModelID;?>" <?php if($obj_queryCarModel->CarmodelID == $CarAdCarModel) { echo 'selected="selected"'; } ?> > <?php echo $obj_queryCarModel->CarModelDesc;?></option> <?php } ?> </select> </label> I'm a novice.. and appreciates all the help ! I am creating a form that will allow the user to select the make of vehicle "FORD" for example. If that make of vehicle is selected among different makes of vehicles, then another box will appear, with all the models for that particular model "Fiesta" for example. What type of code accomplishes this setup in my web page? I do not want to list 500 models in one drop down list, but just those for each make in the first drop down list. Thanks much! Hey Everyone.
I am hoping this is the right place to ask this question.
I am using a new WordPress theme and it has native related post coding in it. The problem is the code uses Post Tags as the selection value instead of Post Category. I was wondering if anyone could help me with this strip of code. I want to change it so the theme gets Posts in the same Category, instead of Posts with the same Tags.
* Display related posts. * * @return void */ function stag_related_posts() { global $post; if( stag_rcp_user_has_no_access() ) return; if( ! stag_theme_mod( 'post_settings', 'show_related_posts' ) ) return; $tags = wp_get_post_tags( $post->ID ); if ( count( $tags ) ) { $tags_ids = array(); foreach($tags as $individual_tag) { $tag_ids[] = $individual_tag->term_id; } $query = new WP_Query( array( 'tag__in' => $tags_ids, 'post__not_in' => array( $post->ID ), 'posts_per_page' => absint( stag_theme_mod( 'post_settings', 'related_posts_count' ) ), 'caller_get_posts' => 1 ) ); // Add filter to attach 'post-grid' class add_filter( 'stag_showing_related_posts', '__return_true' ); if( $query->have_posts() ) : echo '<section class="related-posts" data-layout="2-2-2-2">'; while( $query->have_posts() ) : $query->the_post(); get_template_part( 'content', get_post_format() ); endwhile; echo '</section>'; endif; } wp_reset_query(); remove_all_filters( 'stag_showing_related_posts' ); }I've tried simply replaces the words Tags with Categories, but it doesn't seem to do much. Any help would be greatly, greatly, appreciated. If I have a drop-down list... Code: [Select] <select name="attendees"> <option value="">--</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select> Where does the value that the user selects get stored? Does it get stored in $_POST by default (if a Form is used)? What variable would hold the selected value? Debbie guys i have this dropdown menu echo "<form method=\"post\" action=\"\">"; echo "<center><select name=\"mydropdown\" size=\"0\" style=\"height:4em; width:15em;\">"; echo "<option value=\"Milk1\">{$_SESSION['tem1']}</option>"; echo "<option value=\"Milk2\">{$_SESSION['tem2']}</option>"; echo "<option value=\"Milk3\">{$_SESSION['tem3']}</option>"; echo "</select></center>"; echo "</form>"; and i wand to update a variable every time i select one of the contents... how can i done this??? hello fellas, need some help please if possible. i have created a date of birth section in my form where the user selects his/her date of birth from the dropdown menu. they would first select the day then month then year of their birthday. how would i setup the database to get this to work? i currently have: Code: [Select] day VARCHAR( 2 ) NOT NULL , month VARCHAR( 4 ) NOT NULL , year VARCHAR( 4 ) NOT NULL , is this correct? many thanks Hello, i want to reproduce a content switcher based on drop-down menu (example: http://www.infocercetare.ro/index.php) anyone can help me with the logic of the function the rest i think i can handle. best regards Hello, I am trying to update my database with multiple array values like this. if (isset($_POST['submit_multiple'])) { $id=$_POST['selector']; $class=$_POST['class']; $section=$_POST['section']; $N = count($id); for($i=0;$i<$N;$i++) { echo "update table1 set transfer_status='yes',transfer_date='".date('Y-m-d')."',class='".$class[$i]."',section='".$section[$i]."' where enroll_no='".$id[$i]."'"; }and in the form <form action="transfer_mul_student.php" method="post"><select name="class[]"> <option value="">--SELECT CLASS--</option> <option value="Nursery">Nursery</option> <option value="LKG">LKG</option> <option value="UKG">UKG</option> <option value="I">I</option> <option value="II">II</option> <option value="III">III</option> <option value="IV">IV</option> </select> <select name="section[]"><option value="">--SELECT SECTION--</option> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> </select><input name="selector[]" id="selector" type="checkbox" value="<?php echo $row['enroll_no']; ?>" /> <input type="submit" class="delete_multiple" value="Transer" name="submit_multiple" />Here $row['enroll_no']is from table student. I have attached the screenshot for the page display with form err1.PNG 12.04KB 0 downloads, In that If i select checkbox1, checkbox2 checkbox3.. it takes the value for class and section properly, but if i select checkbox1, checkbox3, it takes value for 1st record properly and for 2nd one it takes blank value for class and section. How to overcome this? Please suggest Need some help to define the php logic to echo back a selection if/when chosen from the drop down menu. Note: I'm using just a small subset of the USA states to show setup and what I'm trying to accomplish - it will be the same for all the other drop down menus as well.... Here's the example code: Code: [Select] <form name="form1" method="post" action="<?php $_SERVER[PHP_SELF]; ?>"> <select name="address_state" id="address_state" tabindex="25"> <option value="" selected> - Select State -</option> <option value="AK">Alaska</option> <option value="AL">Alabama</option> <option value="AR">Arkansas</option> <option value="AZ">Arizona</option> <option value="CA">California</option> <option value="CO">Colorado</option> <option value="CT">Connecticut</option> <option value="DC">District of Columbia</option> </select> <input name="submit" type="submit" value="submit" tabindex="900" id="submit" /> </form> Issue: I have validation (logic) define to check all the (other) text, radio, and check boxes of the form and that all works great! However, any time one of those particular fields fail validation, any selected "drop down" item is lost - it defaults back to no selection and the user has to make all drop down menu selections again. Can someone provide method to echo back - in php being the page reloads to itself - the drop down selection as in the example above? Thanks! This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=341998.0 Hi, I'm using the following code: <td>$row[color]</td> and the possible values for this field are 1, 2 and 3. But I want the return to be red for 1, blue for 2, and green for 3. How do I write it so that instead of getting a row of 1's, 2's and 3's, I change those numbers to their corresponding colors? Thanks! My problem is when the entries in the form are validated and some fields with incorrect entries are found the fields filled out stay on the re-load of the form, all of them except the US States drop down menu which reverts back to Alabama every time. I would like to see that the user selection stays in place even after a re-load of the form. and with my limited experience I am having an issue trying to figure this out for a school project. Any help at all would be greatly appreciated, like what variables to create/call on and where exactly I insert this code. Much appreciated. here is the display code: <?php /* Program name: exercise_4_form.inc * Description: Defines a form that collects a user's * name and mailing address. */ $rows = array( "first_name" => "First Name (optional)", "last_name" => "Last Name", "phone" => "Phone Number", "city" => "City", "state" => "State", "address" => "Address", "zip_code" => "ZIP Code", "e_mail" => "E-Mail"); $states_list = 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"); $submit = "Submit mailing information"; ?> <html> <head> <style type='text/css'> <!-- body { background: #42413C; color: #000; font-family: Tahoma, Geneva, sans-serif; font-size: 90%; } form { margin: 1em 2 2 2; padding: 1; width: 1100px; margin-left: 35%; } .field {padding-bottom: 1em; } label { font-weight: bold; float: left; width: 15%; margin-right: 1em; text-align: right; background-color: #9F6; padding-right: 5px; } select {margin-bottom: 1em;} #submit { margin-left: 15%; } h3 { width: 500px; margin-left: 35%; } --> </style> </head> <body> <h3>Please enter your mailing information below:</h3> <?php /* loop that displays the form */ echo "<form action='$_SERVER[PHP_SELF]' method='POST'>"; foreach($rows as $field => $label) if($field == "state") { echo "<label for='$field'>$label</label> <select id='$field' name='$field'>\n"; foreach ( $states_list as $abbr => $sname ) { echo "<option value='$abbr'>$sname</option>\n"; } echo "</select>\n"; } else { echo "<div class='field'><label for='$field'>$label</label> <input id='$field' name='$field' type='text' value='".@$$field."' size='25%' maxlength='65' /></div>\n"; } echo "<div id='submit'> <input type='hidden' name='submitted' value='yes'> <input type='submit' value='$submit'></div>"; ?> </form> </body> </html>Here is the Logic on the combined php file that displays and has the statements on it for the form: <?php /* Program name: exercise_4_form_verifications.php * Description: Program checks all the form fields for * blank fields and verifies them */ if(isset($_POST['submitted']) and $_POST['submitted'] == "yes") { foreach($_POST as $field => $value) { if(empty($value)) { if($field != "first_name") { $blank_array[] = $field; } } else { $good_data[$field] = strip_tags(trim($value)); } } if(@sizeof($blank_array) > 0) { $message = "<p style='color: black; margin-bottom: 0;font-weight: bold; margin-left: 35%'> You didn't fill in one or more required fields. You must enter: <ul style='color: yellow; margin-top: 0; margin-left: 35%; list-style: none' >"; foreach($blank_array as $value) { $message .= "<li>$value</li>"; } $message .= "</ul>"; echo $message; extract($good_data); include("exercise_4_form.inc"); exit(); } foreach($_POST as $field => $value) { if(!empty($value)) { $name_verify = "/^[A-Za-z' -]{1,50}$/"; $phone_verify = "/^[0-9)(xX -]{7,20}$/"; $city_verify = "/^[A-Za-z' -]{1,50}$/"; $address_verify = "/^[A-Za-z0-9 .,'-]{1,50}$/"; $zip_verify = "/^[0-9]{5}(\-[0-9]{4})?$/"; $e_mail_verify = "/^.+@.+\\..+$/"; if(preg_match("/last/i",$field)) { if(!preg_match($name_verify,$value)) { $error_array[] = "$value is not a valid last name"; } } if(preg_match("/phone/i",$field)) { if(!preg_match($phone_verify,$value)) { $error_array[] = "$value is not a valid phone number"; } } // endif phone format check if(preg_match("/city/i",$field)) { if(!preg_match($city_verify,$value)) { $error_array[] = "$value is not a valid city"; } } if(preg_match("/address/i",$field)) { if(!preg_match($address_verify,$value)) { $error_array[] = "$value is not a valid address"; } } if(preg_match("/zip/i",$field)) { if(!preg_match($zip_verify,$value)) { $error_array[] = "$value is not a valid ZIP code"; } } if(preg_match("/e_mail/i",$field)) { if(!preg_match($e_mail_verify,$value)) { $error_array[] = "$value is not a valid e-mail address"; } } } $clean_data[$field] = strip_tags(trim($value)); } if(@sizeof($error_array) > 0) { $message = "<ul style='color: yellow; margin-top: 0; margin-left: 35%; list-style: none' >"; foreach($error_array as $value) { $message .= "<li>$value</li>"; } $message .= "</ul>"; echo $message; extract($clean_data); include("exercise_4_form.inc"); exit(); } else { echo "<ol>"; foreach($_POST as $field => $value) { echo "<h3><li> $field = $value</li></h3>"; } echo "</ol>"; } } else { include("exercise_4_form.inc"); } ?> Edited by mac_gyver, 15 November 2014 - 12:14 PM. code tags around posted code please I have a form for a sign in page that I want the label for the form field to actually be displayed in the text box and clear when the box is selected to enter text. I've accomplished this using the code below and it works fine. The problem that I'm having is in IE the password field does not change to display dots or asterisk in place of each character. It works fine in Fire Fox but not in IE. Is there way to accomplish this using php or so that it is compatible with most browsers? Here's the code that I'm using: Code: [Select] <?php echo "<input type=\"text\" name=\"pword\" size=\"17\" value=\"Password...\" style=\"color: #999999\" onfocus=\"if (this.value == 'Password...') {this.value=''; this.style.color='#000000'; this.type='password';}\"> "; ?> Can be those <input ...> types with values changed from a script ?. Imagine it like we have an admin and we want to change some input values with a generated form on that page instead of going source and changing 1 by 1 ? Hi Just learning PHP and I'm struggling with a very simple problem. I'm playing around with arrays as i figure they're one of the most important things to know inside out but I can't work out how to change the value of an array element via a loop. I can obviously do it if I just directly write $cars[2] = "test" but not having any luck with the loop. I've tried using "foreach" and passing a new value to the $value variable but when i do a print_r the values in the array are unchanged. Code: [Select] $cars[0]="Saab"; $cars[1]="Volvo"; $cars[2]="BMW"; $cars[3]="Toyota"; foreach ($cars as $key => $value) { $value = "TEST"; echo $key . " " . $value . "<br />"; } print_r($cars) I then tried using a for loop Code: [Select] for ($i=0; $i <= count($cars); $i++) { echo $cars[$i]; $cars[$i] = "2"; } But this code just threw up a fatal error as follows: "Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 16 bytes) in /home/zzzzzzzz/public_html/php_testing/arrays.php on line 27" So would someone be kind enough to explain where i'm going wrong and why i get the fatal error on the second for loop. Thanks Drongo Hi I have an array which looks like this when i do a print_r(): Array ( => Array ( [path] => 1 [order] => 2 ) [1] => Array ( [path] => 2 [order] => 1 ) [2] => Array ( [path] => 3 [order] => 2 ) ) In this instance, I want to change the values of the order key. So I do something like this so that the last array has a path of 3 and an order of 1, and the others have orders of 2 foreach ($old_images as $old_image){ if($old_image['path']==3){ $old_image['order']="1"; } else{ $old_image['order']="2"; } } When i step through, i see that the order is changed, but when i do a print_r(), i get the same result. So even though im resetting the order value of the inside arrays, the multidimensional array does not change.... any ideas? I'm not completely sure how to implement this so I'd like to ask you to give me an idea if you can For a tennis booking system.. it will look something similar to (should be a table but this is for the sake of the idea) Date: Oct 25th, 2010 (go to oct 26) Court 1 Court 2 Court 3 Court 4 8:00 Open(bookit) Tally Open Hellio 9:00 Andy Roger Barney Training ...etc Now everyday, this table should be empty, so new bookings can be made how would I make it so a new table is empty /or has dif bookings every day (based on date) efficiently? Im guessing I will have dif values in the sql table for dif dates but what I'm not sure of is how to display it in page for ex, if someone presses the button oct 26, the new table is for that date, wif diff values Ok I am testing foreach in an array as my practice. I wonder how can I assign values in the key of the array.. Here's the code Code: [Select] <?php $username = me_mysql_prep(trim($_POST['username'])); $first_name = me_mysql_prep(trim($_POST['first_name'])); $last_name = me_mysql_prep($_POST['last_name']); $email = me_mysql_prep($_POST['email']); $position = me_mysql_prep($_POST['Position']); $password = me_mysql_prep($_POST['password']); $hashed_password = sha1($password); $required_fields = array($username,$first_name,$last_name, $email, $position, $password); foreach($required as $key => $value) { if($value == "") { echo $key . " Cannot be empty<br>"; } } ?> So the result would be like this... IF username, first name and last name are EMPTY it will echo: Quote username cannot be empty first name cannot be empty last name cannot be empty Anyone? I posted a topic earlier and there was confusion as to what I could not work out.
I am able to display the checkbox, either checked or unchecked depending of the value or 1 or 0 in the obcDisplay field.
<input type="checkbox" name="obcDisplay" value="<?=$r['obcDisplay'] ?>" <?=($r['obcDisplay']) ? 'checked="checked"' : ''; ?>/>I am trying to update the DB table by the checkbox. If the checkbox is checked (obcDisplay = 1) and I uncheck the box and submit, I want the table updated so that obcDisplay now equals 0. When the form is displayed, the checkbox is now uncheck (obcDisplay = 0). Now I check the box and submit and the update changes the field from 0 to 1. I can display the checkbox as checked or unchecked by the DB field obcDisplay being either 0 or 1. It is changing the value where I am having the problem. Hi all I am trying to write a piece of code that allows a user to select a country from the drop down menu and them submit it so that it changes the delivery cost in the session. Here's the code for the drop down menu: echo "<form method=\"post\" action=\"basket.php\">"; echo "<select name=\"postal_area_name\" >"; echo "<option value=\"\">--Please Select--</option>"; echo "<option value=\"England\">England</option><option value=\"Scotland\">Scotland</option><option value=\"Wales\">Wales</option>"; echo "</select>"; echo "<input type=\"submit\" name=\"submit_postal_area\" value=\"Go\" class=\"go\">"; echo "</form>"; Then here's my code to grab the delivery change from the form: if(isset($_POST['postal_area_name'])) { $_SESSION['postal_area'] = ($_POST['postal_area_name']); header("Location: basket.php"); exit; } Then this is to set the session price: if(isset($_SESSION['postal_area']) && $_SESSION['postal_area'] == "England") { $set_delivery = "5.95"; } elseif(isset($_SESSION['postal_area']) && $_SESSION['postal_area'] == "Wales") { $set_delivery = "10.00"; } elseif(isset($_SESSION['postal_area']) && $_SESSION['postal_area'] == "Scotland") { $set_delivery = "20.00"; } else { $set_delivery = "5.95"; } $subtotal += $set_price * $qty; $delivery += $set_delivery * $qty; Then I echo out the $delivery in the basket. This doesn't seem to update, it shows the value as being 0 all the time? Please help Thanks Pete |