473,385 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Javascript to hide a text box

10
hi,

would you please help me in writing a javascript code to implement a text box that is hidden beside a drop down box.the text box should be enabled only when we select an "others"option from a drop down box.please help me,its urgent.

Thank you in Advance........
May 9 '07 #1
10 19964
acoder
16,027 Expert Mod 8TB
Welcome to TSDN.

Should it be hidden or disabled?

You'll need to use the onchange event on the select:
[HTML]<select ... onchange="...">[/HTML] Call a function that will enable/show the text box. Assuming txtobj is the text box object and selObj is the select object:
Expand|Select|Wrap|Line Numbers
  1. if (selObj.value=="Other") txtobj.disabled=false;
  2. else txtobj.disabled=true;
May 9 '07 #2
avr1983
10
Thank-U for your reply.

The text box should be hidden when we select specifications in given combo box and when we select "others" in that specifications text box should be visible to write into it
May 10 '07 #3
acoder
16,027 Expert Mod 8TB
Post your code/HTML that you've got so far.

Try and follow my first post replacing
Expand|Select|Wrap|Line Numbers
  1. disabled=false
with
Expand|Select|Wrap|Line Numbers
  1. style.visibility='visible'
and
Expand|Select|Wrap|Line Numbers
  1. disabled=true
with
Expand|Select|Wrap|Line Numbers
  1. style.visibility='hidden'
to make visible/hide instead of enable/disable.
May 11 '07 #4
avr1983
10
need a bit clear code....
thank u in advance.....
May 12 '07 #5
acoder
16,027 Expert Mod 8TB
need a bit clear code....
thank u in advance.....
No it doesn't work like that.

What code have you got so far? What errors have you got?
May 14 '07 #6
avr1983
10
exactly what i need is,we have a combo box with some value in it.when i select the value "others" in d combo box i want the text box to be appeared.and for remaining values it should be hidden.
thank u in advance
May 17 '07 #7
acoder
16,027 Expert Mod 8TB
Agan, you'll need to use the onchange event on the select:
[HTML]<select ... onchange="myfun(this)">[/HTML] "this" refers to this element meaning the select element.
In your function, assuming txtobj is the text box object (you know how to access that):
Expand|Select|Wrap|Line Numbers
  1. function myfun(selObj) {
  2.  if (selObj.value=="Other") txtobj.style.visibility='visible';
  3.  else txtobj.style.visibility='hidden';
  4. }
May 17 '07 #8
An alternative to visibility (if I'm not mistaken visibility doesn't work in all browsers, am I correct?) you can use OBJECTNAME.style.display = "none;". As someone else mentioned, what code do you have already?

Anthony
simplesoftsolutions.com
May 17 '07 #9
Hi guys well i have the same prob i have a select list with names of companies
and i have at the end a field called others
i want that when i choose others that an empty appear but ur code didnt work:S
plz help! they told me that it can work with ajax!
May 18 '07 #10
acoder
16,027 Expert Mod 8TB
Hi guys well i have the same prob i have a select list with names of companies
and i have at the end a field called others
i want that when i choose others that an empty appear but ur code didnt work:S
plz help! they told me that it can work with ajax!
Welcome to TSDN.

You don't need ajax for this - it just requires some simple DHTML. Post your code so we can see your problem.
May 21 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Mark | last post by:
Sorry, I'm a newbie to php ;) I was thinking about using php to write the script file, something like: <script type="text/javascript" src="http://insert_url_here.com/myScript.php"></script> ...
12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
4
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
2
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
1
by: Oliver Hoehle | last post by:
Hello! This ist the source-code for an editable combobox implemented with HTML,CSS and Javascript. I have tested it with IE and Mozilla. But I don't know, if it will work in other browsers...
5
by: googlegroups | last post by:
I have a large table in html created dynamically. This table can grow to several hundred rows or more. I have the ability to hide or display individual rows (using row.style.display = "none") and...
47
by: SOLAV | last post by:
This is the only working way to completely hide your JavaScript code from the client just like PHP or ASP code. Here we'll need the help of PHP. Here is the code: index.php...
7
by: hollopeterb | last post by:
my javascript code works great in IE but not in Firefox, can anyone help? Thanks!! Here is the code: <script type="text/javascript"> <!-- function MM_findObj(n, d) { //v3.0 var p,i,x; if(!d)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.