473,320 Members | 1,854 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,320 software developers and data experts.

Hide text box when select one of dropdown value

250 100+
I have 3 text boxes and one dropdown box. Drop down box has 2 values eg: Yes and No. Normally i want to hide last 2 twxt boxes and when user select "No" i want to set visible to the above mention text boxes. How can i do that. I'm using php and my sql.
Feb 8 '08 #1
3 3519
nathj
938 Expert 512MB
I have 3 text boxes and one dropdown box. Drop down box has 2 values eg: Yes and No. Normally i want to hide last 2 twxt boxes and when user select "No" i want to set visible to the above mention text boxes. How can i do that. I'm using php and my sql.
Hi I would do this with some JavaScript that is called on the onchange event of the dropdown box:
Expand|Select|Wrap|Line Numbers
  1. onchange="toggleDisplayState(this.value, __TextBoxID__);"
  2.  
The __TextBoxID__ needs to eb the id you assigned to the text boxes or the DIV that contains them - basically it's the id of the item you want to hide.
Expand|Select|Wrap|Line Numbers
  1. function toggleDisplayState(pcValue, poObjectToDisplay)
  2. {                                                         
  3.  
  4.     var loObject = document.getElementById(poObjectToDisplay);
  5.  
  6.     //test the current state of the object and toggle opposite state.
  7.     if (pcValue == 'yes') // hide boxes
  8.     {
  9.         loObject.style.display = 'none';
  10.      }
  11.     else 
  12.     {
  13.         loObject.style.display = 'inline';
  14.     } 
  15. }
Does this help you out?

Cheers
nathj
Feb 8 '08 #2
ghjk
250 100+
Please tell me where i put this function. Because i put it in my code. But nothing happened.
Feb 8 '08 #3
nathj
938 Expert 512MB
Please tell me where i put this function. Because i put it in my code. But nothing happened.

Hi ghjk,

You have two choices:
1. Use the script tags in the <head> section of the page and have the function listed there.
2. Use the script tags in the <head> section to reference an external *.js file that contains the function.

My preference is the second option. I normally have a file called functionlibrary.js and all my JS functions are listed in there, normally organised by what they do.

Take a look at this tutorial

cheers
nathj
Feb 8 '08 #4

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

Similar topics

6
by: Steve Speirs | last post by:
Hi I'm trying to show/hide a simple piece of text and a text field on a form based on what choice is made from a drop down box. <select name="dropdown" size="1"> <option selected...
20
by: Dannyboyo | last post by:
I have what I hope is a simple request. I can't really code in javascript, but I am pretty good at cusomizing it with slight modifications. I code in ASP and HTML. I am trying to capture customer...
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...
3
by: veganeater | last post by:
Hi, I'm wondering if there's a way that I can select which <div> to show based on the user's selection from a dropdown/listbox form. <form name="form1" method="post" action=""> <select...
8
by: Lyn | last post by:
Hi, Can anyone tell me how the initial value displayed in Combo Box is determined when a form is opened? I am loading the dropdown from one field ("CategoryName") of a table, with "ORDER BY ". ...
6
by: Mark | last post by:
I have two dropdown lists. Both have autopostback set to true. In both dropdowns, when you select an item from the list, it redirects to the Value property of the dropdown. Nothing fancy. ...
3
by: bhanubalaji | last post by:
hi, I am unable to disable the text(label) in javascript..it's working fine with IE,but i am using MOZILLA.. can any one help regarding this.. What's the wrong with my code? I am...
2
by: bhuvragu | last post by:
Hi , Refer to my previous post "Arrow keys Scrolling on Div" , I created a text search with html_ajax. When you type text , it would display the search result in dropdown box under the textbox like...
18
by: Academia | last post by:
I let the use modify the text of a combobox and then I replace the selected item with the new text (in Keyup event). But if he sets the Text property to an empty string ("") that sets the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.