calvin Posted July 21, 2004 Posted July 21, 2004 Hi, I need to visible a textbox and RequiredFieldValidator when user select the item in dropdownlist before click the submit button. The autopostback of dropdownlist is set to false and textbox & Validator visible also set to false. I want to call function in client script(Javascript) to call out the textbox. For example, If select item "Other", then the textbox is visible to enter data. The control to validate of requiredfieldvalidator is set to this textbox. Other than that item will hide the textbox & validator. I using ASP.NET with VB to do the data entry form. Thank you. Calvin Quote
Rodenberg Posted July 21, 2004 Posted July 21, 2004 You should place your textbox inside a <DIV> tag, set the ID of the div tag to something like "div_txt" or whatever and write a javascript function that sets the visibility of the tag based off of the current value of an element passed to the function. Then just set the drop down list to call the function when the text changes, passing itself as the parameter. like this: <SCRIPT language=javascript> function SetVis(element){ if(element.value == "Other"){ document.getElementById('div_txt').style.visibility= 'false'; } else document.getElementById('div_txt').style.visibility= 'true'; } </SCRIPT> ...html down here... <DIV style='VISIBILITY:true;' id='div_txt'> <ASP:TEXTBOX id='txt' runat='server'> </DIV> <ASP:DROPDOWNLIST id='cboList' runat='server'> Now add the following in your codebehind page_load event: this.cboList.Attributes.Add("ontextchanged","SetVis(this);"); Hope this helps, Ron Quote
calvin Posted July 21, 2004 Author Posted July 21, 2004 Dear Ron, I get an error message of "Object Expected". I can't write the code below in page_load, the"this" get error of "Name 'this' is not delared". Your code: this.cboList.Attributes.Add("ontextchanged","SetVis(this);"); I changed it to My code: cboList.Attributes.Add("ontextchanged","SetVis();"); What for we need to put "this" in code? Instead of this, what I need to do? :confused: Thank you Ron for help Calvin Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.