File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes creating a text box if the option is Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "creating a text box if the option is "other" from the drop down by javascript" Watch "creating a text box if the option is "other" from the drop down by javascript" New topic
Author

creating a text box if the option is "other" from the drop down by javascript

ranjan panda
Greenhorn

Joined: Oct 03, 2005
Posts: 8
Hi,
The case is there is a drop down in my xsl where in if my user selects the "other" option then a text box should be rendered in the resulting HTML so that the user can write a name which does not exist in the drop down.
Is the following the right approach?
function checkOther(){
var sel = document.MainForm.CurrentInsurer.value;
}
I am using javascript for the first time. So who ever want to help me write the complete code for the javascript function and the code for how to call that function from my drop down <select> tag.

Thank you.
Ranjan
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Basic idea



Eric
Ketan Joshi
Ranch Hand

Joined: Oct 09, 2005
Posts: 66
Hi Ranjan,

As you can see from the idea posted by Eric,

It is necessary that your html already contains the text box with initial

style set to none

<input type="text" name="B" id="B" style="display:none">

once the other value is selected from select list we execute the javascript function which changes the style of the text box from none to may be "inline" so that the textbox is visible

to change the style of the textbox,first fetch the id of the text box
and change the display property of style as follows:

document.getElementById("B").style.display="inline"; //execute this only if the other value from select list is selected

Method 2:

This method does not require that a textbox is already created

You create the textbox on the fly
if (other value from select list is selected)

execute the following code in the javascript function
{
var txt=document.createElement("<INPUT TYPE='text'NAME='textfield'>");
document.body.insertBefore(txt);
}

This is on the fly creation of textbox

Hope that helps

Ketan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: creating a text box if the option is "other" from the drop down by javascript