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.

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.