• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basic idea



Eric
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Police line, do not cross. Well, this tiny ad can go through:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic