Question

I am using the following two scripts to update a textarea in a form with the selected value from the dropdown. In isolation they both work correctly however, I am trying to combine them so that changing one dropdown does not overwrite the selected value from the second dropdown which is already present in the textarea. So when the value in the first dropdown changes only this portion of the text in the textarea will be updated and the value from the second dropdown remains and its not deleted (as is currently happening).

<!-- script starts -->
<script type="text/javascript">  
$(document).ready(function() {
$("#imageSize").change(function() {
   $("textarea[name=m1_description]").val($(this).val());
});
});
</script>

<script type="text/javascript">  
$(document).ready(function() {
$("#image").change(function() {
   $("textarea[name=m1_description]").val($(this).val());
});
});
</script>
<!-- script ends --> 

<textarea name="m1_description" cols="80" rows="3" class="cms_textarea"></textarea>

Is this possible? Thanks.

Was it helpful?

Solution

Try changing:

$("textarea[name=m1_description]").val($(this).val());

to

$("textarea[name=m1_description]").val($('#imageSize').val() + $('#image').val());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top