0

I have done an option / list box in html form in which if i click 'Other' option, it will display an additional text field. I create the additional text field through javascript. The code is as below

<select name="how" class="subtitle" id="select" onchange="showfield(this.options[this.selectedIndex].value)" style="width: 200px; height:30px;">>
                          <option selected="true" style="display:none;">Please select</option>
                          <option>School</option>
                          <option>Consultant</option>
                          <option>WhatApp</option>
                          <option>Brochure / Poster</option>
                          <option>Internet</option>
                          <option>Other</option>  
                        </select></td>

Java Script is as below

document.getElementById('div1').innerHTML='Other: <input id="othr" type="text" name="other" />';

It creates the text filed when 'Other' option is chosen. But how to get the value of other text field as the input tag is in the java script.

aynber
  • 22,380
  • 8
  • 50
  • 63
Rajesh
  • 195
  • 1
  • 2
  • 15
  • Possible duplicate of [Get the value in an input text box](http://stackoverflow.com/questions/4088467/get-the-value-in-an-input-text-box) – Caleb Anthony Sep 14 '16 at 21:25

1 Answers1

1

Plain JS:

var val = document.getElementById('othr').value

More info: https://stackoverflow.com/a/11563667/4669619

jQuery:

var val =  = $('#othr').val();

More info: https://stackoverflow.com/a/15903284/4669619

Community
  • 1
  • 1
Ali
  • 558
  • 7
  • 28