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.
Hide text box when select one of dropdown value
Collapse
X
-
Hi I would do this with some JavaScript that is called on the onchange event of the dropdown box:Originally posted by ghjkI 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.
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.Code:onchange="toggleDisplayState(this.value, __TextBoxID__);"
Does this help you out?Code:function toggleDisplayState(pcValue, poObjectToDisplay) { var loObject = document.getElementById(poObjectToDisplay); //test the current state of the object and toggle opposite state. if (pcValue == 'yes') // hide boxes { loObject.style.display = 'none'; } else { loObject.style.display = 'inline'; } }
Cheers
nathj -
Originally posted by ghjkPlease 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
nathjComment
Comment