Rajesh Rajesh - 1 month ago 4x
HTML Question

getting value of other field from javascript which is a part of select tag html

I have a select tag in my html form. In that, if you select 'Other' option you will get a new text box below which is generated through java script. Now I am able to get the value of select tag since it is in the html form itself. But unable to get the data from other text field as it is in javascript. Here is my full sample code.

if(isset($_POST["sub"])) {
//insert query will go here
<script type="text/javascript">
function showfield(name){
if(name=='Other') {
document.getElementById('div1').innerHTML='Other: <input id="othr" type="text" name="other" />';
else {
<form action="form.php" method="post">
<select name="options" id="select" onchange="showfield(this.options[this.selectedIndex].value)" style="width: 200px; height:30px;">
<option selected="true" style="display:none;">Please select</option>
<option>Brochure / Poster</option>
<input type="submit" name="sub">


A simple way is to add <input type="hidden" name="other" value=test /> and update it with js and then it will be a part of the form