Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript onChange Textbox 1

Status
Not open for further replies.

DB2Problem

Programmer
Oct 17, 2002
53
0
0
US
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
 
If you add a DIV right after the select element, and save code by passing the title as a parameter:

Code:
<select name="title" class="form" [!]onchange="addField(this.value);"[/!]>
   <option value="Mr">Mr</option>
   <option value="Mrs">Mrs</option>
   <option value="Others">Others</option>
</select>
[!]<div id="otherFieldContainer"></div>[/!]<br>

then you can use:

Code:
function addField(theTitle) {
   if(theTitle  == 'Others') {
      document.getElementById('otherFieldContainer').innerHTML = '<input type="text" name="otherTitle" size="10">';
   }
}

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top