0

What I am trying to do is when a item is selected from my dropdown menu, it would make a input box appear with the description selected on the dropdown menu, so that it can be edited and updated back into the database,

I am unsure how to handle the javascript:

Dropdown Code:

<select name="captionSelect" id="captionSelect"> <?php foreach ($get_images as $image){ echo '<option value="'.$image['id'].'">'.$image['description'].'</option>'; }; ?> </select> 

2 Answers 2

1

Assuming your input has id 'captionInput', here's a sample code to show the input with dropdown's selected value:

$('#captionSelect').change(function(){ $('#captionInput').val($("#captionSelect option:selected").text()).show(); }); 
Sign up to request clarification or add additional context in comments.

2 Comments

Thank You, This works fine but in my code the value is the ID and the value text is what I am wanting to show in the text box is this possible?
This code will show the description. If you want value, then use $(this).val()
0

Add an onchange event to the select which calls a function. That function can either update another element directly OR do an ajax call to grab the description on the fly.

1 Comment

Yes I understand that but what I do not understand is the correct way to to this can you link to an example?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.