PHP - Change Textboxes From Dropdown Value
Similar Tutorialsi am new to web designing,
i don't know much about javascript.
<select id="plan" align="center" valign="center"> I'm new to this form and php/mysql so sorry if this isn't the right place to post this. This is what is in the first dropdown box. Code: [Select] $selValues['john'] = "a, b, c, d, e"; These are the different lists I want it to put in the second drop down box depending on what they choose in the first. Code: [Select] $selValues['list1']= " a1, a2, a3, a4, a5"; $selValues['list2']= " b1, b2, b3, b4, b5"; This is how I made an attempt to make it work before posting here. Along with plently of other ways. Code: [Select] if ($selValues['john']=a) { $chan_input = selectBuilder($selValues['$list1'] }; else if ($selValues['john']=b) { $chan_input = selectBuilder($selValues['$list2'] }; Basicly how I need it to work is there are two drop down boxes. First they will chose between a,b,c,d,e. If they chose a then on the second drop down box I only want them to be able to select a1,a2,a3,a4,a5. This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=305930.0 Hi there, I am working on a PHP form and running a loop to generate textboxes at runtime. This code output the textboxes: foreach ($MyTest as $tst) { echo "<input name='testName' type='text' size='12' maxlength='5' />"; } I am able to display (or output) 4 or sometimes 6 textboxes depending on the variable $MyTest. Now after I enter the values in these texboxes. Lets say, it outputs 3 textboxes, I woud like to display the values like: In Textbox 1 you entered: In Textbox 2 you entered: In Textbox 3 you entered: How can I get (or fetch) values from the textboxes generated through the loop. Please reply. All comments and feedbacks are always welcomed! Thank you hello, i'm actually doing a javascript here to create dynamic textboxes when a button is clicked. now my problem is, how to get all the values from these textboxes and save these values altogether in a column on the table.. i know few php coding methods like $_POST in handling values from txtboxes and saving it to database but it doesn't include working with javascript and dynamic textboxes.. and i'm actually doubtful if this is possible..so any help from you guys i would deeply appreciate. heres my code: Code: [Select] <html> <head> <script type="text/JavaScript"> function AddTextBox() { document.getElementById('container').innerHTML+='<input type="text" name="block"><br>'; } </script> </head> <body> <input type="text" name="block"> <div id="container"></div> <br> <button onclick="AddTextBox();">Add another textbox</button> </body> </html> 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" /> I have a form with dropdown list that is populated with values from Sql Server table. Now i would like to use this selected item in SQL query. The results of this query should be shown in label or text field. So when a user selects item from dropdown menu, results from SQL query are shown at the same time. I have two dropdown list at the moment in my form. First one gets all values from a column in table in SQL Server. And the second one should get a value from the same table based on a selection in first dropdown list.
When i load ajax.php i get 2 error mesages: This is my code so far. I have tried to do it with this Ajax script. But i can only get first dropdown to work. The second dropdown(sub_machinery) does not show values, when first dropdown item is selected. The second dropdown should show values from databse table with this query( *$machineryID* is first dropdown selected item): SELECT MachineID FROM T013 WHERE Machinery=".$machineryID. Index.php <!doctype html> <?PHP $server = "server"; $options = array( "UID" => "user", "PWD" => "pass", "Database" => "database"); $conn2 = sqlsrv_connect($server, $options); if ($conn2 === false) die("<pre>".print_r(sqlsrv_errors(), true)); echo " "; ?> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <section id="formaT2" class="formaT2 formContent"> <div class="row"> <div class="col-md-2 col-3 row-color remove-mob"></div> <div class="col-md-5 col-9 bg-img" style="padding-left: 0; padding-right: 0;"> <h1>Form</h1> <div class="rest-text"> <div class="contactFrm"> <p class="statusMsg <?php echo !empty($msgClass)?$msgClass:''; ?>"><?php echo $statusMsg; ?></p> <form action="connection.php" method="post"> <div>machinery</div> <select id="machinery"> <option value="0">--Please Select Machinery--</option> <?php // Fetch Department $sql = "SELECT Machinery FROM T013"; $machanery_data = sqlsrv_query($conn2,$sql); while($row = sqlsrv_fetch_array($machanery_data) ){ $id = $row['Id']; $machinery = $row['Machinery']; // Option echo "<option value='".$id."' >".$machinery."</option>"; } ?> </select> <div class="clear"></div> <div>Sub Machinery</div> <select id="sub_machinery"> <option value="0">- Select -</option> </select> <input type="submit" name="submit" id="submit" class="strelka-send" value="Insert"> <div class="clear"> </div> </form> </div> </div> </div> </div> </section> </script> <script type="text/javascript"> $(document).ready(function(){ $("#machinery").change(function(){ var machinery_id = $(this).val(); $.ajax({ url:'ajaxfile.php', type: 'post', data: {machinery:machinery_id}, dataType: 'json', success:function(response){ var len = response.length; $("#sub_machinery").empty(); for( var i = 0; i<len; i++){ var machinery_id = response[i]['machinery_id']; var machinery = response[i]['machinery']; $("#sub_machinery").append("<option value='"+machinery_id+"'>"+machinery+"</option>"); } } }); }); }); </script> </body> </html> Ajaxfile.php <?php $server = "server"; $options = array( "UID" => "user", "PWD" => "pass", "Database" => "database"); $conn2 = sqlsrv_connect($server, $options); if ($conn2 === false) die("<pre>".print_r(sqlsrv_errors(), true)); echo " "; $machineryID = $_POST['machinery']; // department id $sql = "SELECT MachineID FROM T013 WHERE Machinery=".$machineryID; $result = sqlsrv_query($conn2,$sql); $machinery_arr = array(); while( $row = sqlsrv_fetch_array($result) ){ $machinery_id = $row['ID']; $machinery = $row['MachineID']; $machinery_arr[] = array("ID" => $machinery_id, "MachineID" => $machinery); } // encoding array to json format echo json_encode($machinery_arr); ?>Edited May 6, 2019 by davidd Hi freaks, I'm new to php first of all. I'm dynamically binding a dropdownlist with mysql database . After the user selects an item from it , I want to match that item with another table so as to populate another database. The code I'm using to populate dropdown: Code: [Select] <?php $con = mysql_connect("localhost","root",""); if(!$con) { die ('Can not connect to : '.mysql_error()); } mysql_select_db("ims",$con); $result=mysql_query("select cat_id,cat_name from category"); echo "<select name=cat>"; while($nt=mysql_fetch_array($result)) { echo "<option value=$nt[cat_id]> $nt[cat_name] </option>"; } echo "</select>"; mysql_close($con); ?> Now after the user selects any one of the item , I want to bind another dropdown on the same page using such query like $result=mysql_query("select subcategory.sc_id,subactegory.sc_name from subcategory,category where subcategory.sc_id=$nt[cat_id]"); Please anyone tell me the logic and code to do it. Also tell me do I need an intermediate page to post the 1st dropdown value and then continue with 2nd dropdown. I couldn't figure out the concept anyhow. Help on this will be highly appreiable . (Tell me if I'm not clear with my question) I am not a developer but I can modify code to work for me. The following code works on my test machine (Windows 10, IIS, PHP 7.4) but doesn't work on my website (cPanel, Some version of Linux, PHP 7.4). The two dropdowns are for State and City. You are supposed to be able to select the state and then select a city from that state then bring up a report for craft breweries in the city. When selecting State from the first dropdown, the page refreshes, the URL is correct with the reports.php?cat=<STATE> so $cat is being set, but the first dropdown no longer has the state selected and the second dropdown is populated with All cities and not just one ones from the selected state. Any ides why this is working fine on one machine and not the other? Selected code from reports.php
<?php
?>
/////// for second drop down list we will check if State is selected else we will display all the cities/////
echo "<form method=post action='brewerylistbycity.php'>";
}
////////// Starting of second drop downlist /////////
//// End Form /////
Hi, I'm wondering how i would go about making a drop down menu in php to insert the option into users > Maint of my database, if anyone has any tutorials or examples it would be great, Thanks a lot. Hi all. I kinda need some from a more advanced PHP expert. I have a table that displays time slots that are available to be booked. As you can see I have a table with two columns, The 1st column displays the times and the 2nd column has a link that says 'Available'. I want to be able to put all this in a select dropdown box to save space, but how can I do this?
<?php $doc = JFactory::getDocument(); $doc->addStyleSheet(JURI::root(false)."components/com_pbbooking/user_view.css"); ?> <style> table#pbbooking td, table#pbbooking th {padding: 0em;} </style> <h1><?php echo JText::_('COM_PBBOOKING_DAY_VIEW_HEADING').' '.Jhtml::_('date',$this->dateparam->format(DATE_ATOM),JText::_('COM_PBBOOKING_DAY_VIEW_DATE_FORMAT'));?></h1> <table id="pbbooking"> <!-- Draw header row showing calendars across the top....--> <tr> <th></th> <!-- first column left blank to display time slots --> <?php foreach ($this->cals as $cal) :?> <th><?php echo $cal->name;?></th> <?php endforeach;?> </tr> <!-- draw table data rows --> <?php while ($this->day_dt_start <= $this->dt_last_slot) :?> <?php $slot_end = date_create($this->day_dt_start->format(DATE_ATOM),new DateTimezone(PBBOOKING_TIMEZONE));?> <?php $slot_end->modify('+ '.$this->config->time_increment.' minutes');?> <tr> <th><?php echo Jhtml::_('date',$this->day_dt_start->format(DATE_ATOM),JText::_('COM_PBBOOKING_SUCCESS_TIME_FORMAT'));?></th> <?php foreach ($this->cals as $cal) :?> <td class="pbbooking-<?php echo (!$cal->is_free_from_to($this->day_dt_start,$slot_end)) ? 'free' : 'busy';?>-cell"> <?php if ($this->day_dt_start>date_create("now",new DateTimeZone(PBBOOKING_TIMEZONE)) && !$cal->is_free_from_to($this->day_dt_start,$slot_end)) :?> <a href="<?php echo JRoute::_('index.php?option=com_pbbooking&task=create&dtstart='.$this->day_dt_start->format('YmdHi').'&cal_id='.$cal->cal_id);?>"> <?php echo (!$cal->is_free_from_to($this->day_dt_start,$slot_end)) ? JText::_('COM_PBBOOKING_FREE') : JText::_('COM_PBBOOKING_BUSY');?> </a> <?php else :?> <?php echo JText::_('COM_PBBOOKING_BUSY');?> <?php endif;?> </td> <?php endforeach;?> </tr> <?php $this->day_dt_start->modify('+ '.$this->config->time_increment.' minutes');?> <?php endwhile;?> <!-- end draw table data rows--> </table> I'm trying to have it shows the data from my array as each option will have a value of the user's id and the text for the option will be their name. As of right now it only shows the last person. Code: [Select] <?php echo form_label('Recipient', 'recipient'); ?> <?php $data = array( 'name' => 'to', 'class' => 'required' ); <?php echo form_label('Recipient', 'recipient'); ?> <?php $data = array( 'name' => 'to', 'class' => 'required' ); $options = array(); foreach($users AS $user) { $options = array ( $user->user_id => $user->first_name.' '.$user->last_name ); } ?> <?php echo form_dropdown($data, $options); ?> I currently have a web page which the user selects the value from the drop menu. I then want that value to go into another form in the same page inside a hidden field. Which will then be submitted to the processing php. The second option is the user selects the drop menu then the processing php would have to grab the value without a submit button because I am using a save button on the same page in the other form. Any help Hi, I have a dropdown box, and I want it so that if dropdownbox.value='selected:' then show error message. The checkbox is dynamically populated. Pleaee Advise, - stuart Hi, I'm trying to create a dropdown box that is filled by a mysql column. I found this example, which fills the dropdown box with a list of columns in the database, but I want to fill the drop down box with the content in a column. Any guidance on how to do this would be appreciated. Thank you! Example: $connection = mysql_connect("localhost","username","password"); $fields = mysql_list_fields("database", "table", $connection); $columns = mysql_num_fields($fields); echo "<form action=page_to_post_to.php method=POST><select name=Field>"; for ($i = 0; $i < $columns; $i++) { echo "<option value=$i>"; echo mysql_field_name($fields, $i); } echo "</select></form>"; Hi guys. I am having a hard time finding a solution for this, is it possible to get not the value of a dropdown (oh what's it called??? ) but what is in between of the <option> tag?like, Code: [Select] <select name="catID"> <option value=$row['c_id']>$row['c_name']</option> and save it to the database??cuz I'm using a dynamic dropdown which bases the content of another dropdown by the id of the previous. And so, if i save it to the database, instead of for example "BSA" is saved, the id of "BSA" which is "1" is saved..any ideas guys? Hello, I am searching to find an answer to my question but without success. I have a HTML dropdown list like this: <select name="ports"> <option value="10">1/1/1/0/shdsl</option> <option value="12">1/1/2/0/shdsl</option> <option value="14">1/1/3/0/shdsl</option> <option value="16">1/1/4/0/shdsl</option> <option value="18">1/1/5/0/shdsl</option> <option value="20">1/1/6/0/shdsl</option> <option value="22">1/1/7/0/shdsl</option> <option value="24">1/1/8/0/shdsl</option> <option value="26">1/1/9/0/shdsl</option> <option value="28">1/1/10/0/shdsl</option> <option value="30">1/1/11/0/shdsl</option> <option value="32">1/1/12/0/shdsl</option> <option value="34">1/1/13/0/shdsl</option> <option value="36">1/1/14/0/shdsl</option> <option value="38">1/1/15/0/shdsl</option> <option value="40">1/1/16/0/shdsl</option> <option value="42">1/1/17/0/shdsl</option> <option value="44">1/1/18/0/shdsl</option> <option value="46">1/1/19/0/shdsl</option> <option value="48">1/1/20/0/shdsl</option> <option value="50">1/1/21/0/shdsl</option> <option value="52">1/1/22/0/shdsl</option> <option value="54">1/1/23/0/shdsl</option> <option value="56">1/1/24/0/shdsl</option> </select> All I want to do is to get the value & the text (e.g 56 & "1/1/24/0/shdsl"). I get the value (say 56) with: $_POST['ports'] Could you please help me get the text? |