Jump to content
Xtreme .Net Talk

Visible the text box after select the item in dropdownlist but before postback in cli


Recommended Posts

Posted

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

Posted

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

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...