JeffH13 Posted January 6, 2015 Report Posted January 6, 2015 My first attempt to create dropdown box. I was able to get the information to correct show up but I'm a little confused on how to transfer it. Here is the old line of code where I hand type in information <td width="100" height="27" align="center" valign="top" bgcolor="#FFFFFF" class="style20"><input type="text" name="msdstype" value="<?php echo $msdstype; ?>"/></td> I have created this dropdown box which does show the values available. <select name="dropdown"> <?php typequery() ?> </select> But after the value is selected and I go to enter next field I want that value to go into "msdstype" Thanks any insight will be helpful. Quote
falkencreative Posted January 6, 2015 Report Posted January 6, 2015 So, just so I understand the process... You have two fields -- one dropdown, and one text field? And when a user selects from the dropdown, you want the value from the dropdown to automatically be added to the text field? I'm assuming you need that text field because the user may be editing the content? You'd need to do that with Javascript. -- In pure Javascript, you'd want to use the onChange event (http://www.w3schools.com/jsref/event_onchange.asp), which would get the value from the dropdown (http://www.w3schools.com/jsref/met_doc_getelementbyid.asp) and set the value of the text field (http://stackoverflow.com/questions/4541855/how-do-i-set-value-of-a-textbox-using-javascript) -- If you're using jQuery, it would be similar, using change() (http://api.jquery.com/change/) to check when the value of the dropdown changes, find the value (http://learn.jquery.com/using-jquery-core/faq/how-do-i-get-the-text-value-of-a-selected-option/) and set the value of the text field (also using val() http://api.jquery.com/val/) Quote
JeffH13 Posted January 7, 2015 Author Report Posted January 7, 2015 Sorry Ben that not what I was trying to say but I do understand how you came up with that. Ok me try this again. The page I have I'm entering new data, the field "msdstype" I want to limit the the field options so I created a dropdown. But once that dropped has been select which is coming from a different table called typeinfo and the field from that table is called typename. How do i get that value that has been selected to be placed in the database. Quote
falkencreative Posted January 7, 2015 Report Posted January 7, 2015 Assuming I'm understanding you correctly... So you have a single dropdown field that the user can select from. And you want to save their selected value in the database? In that case, you'd name the dropdown using the name attribute (which in your code above you named "dropdown"), you'd have the user submit the form, you'd retrieve the dropdown value using $_POST['dropdown'], and you'd use that value when creating an SQL query that would save it in the database using an SQL insert statement. I guess I'm just not sure what part of that process you are confused about? It works exactly the same way as using a regular text input and saving that value to a database. If your existing PHP script which processes the form and saves the values to the database is expecting to get that data from a field named msdstype, you'd just want to name your select "msdstype" rather than "dropdown", and everything else should work fine. Quote
JeffH13 Posted January 13, 2015 Author Report Posted January 13, 2015 Thanks so much Ben. I works great. Quote
JeffH13 Posted January 19, 2015 Author Report Posted January 19, 2015 Ben, I based my view edit delete add off of your forum topic. http://www.killersites.com/community/index.php?/topic/1969-basic-php-system-vieweditdeleteadd-records/ I was able to incorporate the Dropdowns on the new page how would approach placing the drop down in the edit page. I want to show what the current selection is but also show the possibilities per field. I'm converting an old MS Access database that we are using. This is a screen shot of that. Thanks any guidance you can give me would be greatly appreciated. Thanks!! Quote
falkencreative Posted January 19, 2015 Report Posted January 19, 2015 The easiest solution would be to show the dropdown -- same as you would in the "create new" page -- but have the default selected state be whatever that field is set to. That's pretty straight-forward. You'd want to create the dropdown in the same way that you created the dropdown on the create new page, but for every option you create in your dropdown, you check to see if the value of that option matches the selected option, and if so, give that the "selected" attribute. http://www.w3schools.com/tags/att_option_selected.asp So, something like this... <select name="selectname"> <option value="optionvalue" <?php if($selectedname == 'optionvalue') { echo 'selected'; } ?>>Option Name</option> </select> So in this case, you'd need to change the "selectname" to whatever you've named the select, and any values/names as appropriate. $selectedname is whatever value the user had selected for that field when they originally created the record. Quote
JeffH13 Posted January 19, 2015 Author Report Posted January 19, 2015 Thanks I'll give it a try tonight hopefully... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.