Javascript onChange Textbox

Hello All

I have this select drop down

<select name="title" class="form" onChange="javascript:addField();">
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Others">Others</option>
</select><br>

This is somewhere in my JSP page. On Change of title as Other, I need to bring a textbox right under this

select drop down.

function addField(){
if(MainForm.title.options[MainForm.title.selectedIndex].value == "Others"){
// need to do some code to place the textbox under select drop down
}
                  

How can I place the textbox exactlt at that place. I don't know. Any help will be greatly appreciated

Thanks
Java_ProblemAsked:
Who is Participating?
 
shaggy_the_sheepCommented:
Hi

You could put the text box where you want it. Just enclose it with a span. Give this span an id such as <span id="OthersTextBox" style="display: none"><TEXTBOX STUFF IN HERE></span>

The style display: none will ensure that the box is hidden to begin with.

Now with the selec box just change your script to this...

function addField(){
if(MainForm.title.options[MainForm.title.selectedIndex].value == "Others"){
   document.getElementById('OthersTextBox').style.display = 'block';
   }
else{
//This will hide the box if someone previously chose other but the changed their mind.
   document.getElementById('OthersTextBox').style.display = 'none';
   }
}

Let me know if you need anything else

Richard
0
 
Java_ProblemAuthor Commented:
Thanks a lot
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.