Diaan Last
Diaan Last

Reputation: 81

Get input from text area

How to show latitude and longitude in textarea. What seems to be the wrong in this code? Thank you

HTML :

  Locations:
  <select name="ctrTitles" id="ctrTitles">
    <option value="1">School</option>
    <option value="2">Office</option>

  </select>

  <textarea name="inputList" id="inputList" cols="50" rows="5" readonly="readonly"></textarea>
  <input type="button" value="Proses" onclick="clickedAddList()">
  <input id="button2" type="button" value="Calculate" onclick="directions(1, false, false, false, false)">
 <input id='button3' type='button' value='Reset' onclick='startOver()'>

JS:

var centerLocations = {}

text1: -9.683075, 124.1241341 - 10.258829, 123.553435 - 10.1965777, 123.5305067,
  text2: -9.853080, 124.268283 - 10.115900, 123.809843 - 9.874031, 124.249636
};

$('#ctrTitles').change(function() {
  $("inputList").val(centerLocations["text" + this.value]);
}).change();

Upvotes: 2

Views: 71

Answers (1)

Tushar
Tushar

Reputation: 87203

You missed the # in

$("inputList").val(centerLocations["text" + this.value]);

Should be

$("#inputList").val(centerLocations["text" + this.value]);

Also, the object centerLocations is not defined correctly. The values should be wrapped in quotes.

Should be as follow:

var centerLocations = {
    text1: '-9.683075, 124.1241341 - 10.258829, 123.553435 - 10.1965777, 123.5305067',
    text2: '-9.853080, 124.268283 - 10.115900, 123.809843 - 9.874031, 124.249636'
};

Demo

var centerLocations = {
  text1: '-9.683075, 124.1241341 - 10.258829, 123.553435 - 10.1965777, 123.5305067',
  text2: '-9.853080, 124.268283 - 10.115900, 123.809843 - 9.874031, 124.249636'
};

$('#ctrTitles').change(function() {
  $("#inputList").val(centerLocations["text" + this.value]);
}).change();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
Locations:
<select name="ctrTitles" id="ctrTitles">
  <option value="1">School</option>
  <option value="2">Office</option>
</select>

<textarea name="inputList" id="inputList" cols="50" rows="5" readonly="readonly"></textarea>
<input type="button" value="Proses" onclick="clickedAddList()">
<input id="button2" type="button" value="Calculate" onclick="directions(1, false, false, false, false)">
<input id='button3' type='button' value='Reset' onclick='startOver()'>

Upvotes: 2

Related Questions