Click here to Skip to main content
15,924,507 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Today I got one interesting problem. I am working on SMS management so I have one dropdown to select template , after selecting template the same text should be apear on message body which is a text area and it is in the same jsp page. Some of my friends suggest me to do in Ajax but I dont know Ajax can any help me to solve this . Here is my select and textare elements.

HTML
<select class="selectpicker form-control"
            name="grade" data-style="btn-primary">
            <option></option>
            <c:forEach var="grade" items="${gradeInfo}">
                <option value="${grade.getDropDownName()}">${grade.getDropDownName()}</option>
            </c:forEach>
</select>

<div class="input-group input-group-lg" >
               <span class="input-group-addon">Message</span>
            <textarea class="form-control " rows="6" placeholder="Message"
                style="height: auto;" id="MessageBox"></textarea>
</div>



Here dorpdown values come from database . If I select one value the same text should apear on textarea. Please Help me in this.
Posted

Since it appears that, in your dropdown, the text and value are the same, you could use the DOM to easily grab the selected text item and write it elsewhere.

You need to give any items you wish an id='something', each something unique from other somethings on the page.

To get the value selected in the drop down:
Add an onchange="" event to the Dropdown

In the onchange event you'd get the currently chosen value:

<script type = 'text/javascript'>
 function Handler_for_onchant() {
  var picked = document.getElementById('your_select_control_ID').value;
  // now update the textbox:
  document.write.getElementById('your_textbox_control_ID').value = picked;
</script>


You should get proficient with DOM if you wish to do web development
 
Share this answer
 
v3
I used Jquery as follow

JavaScript
$('select').change(function(){ $('textarea').val( $(this).find('option:selected').text() ) }).change();



it also worked.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900