0

I'm trying to write javascript code where there is an object called "costCenter" which the visibility should be false. but when i click on the "computer" item on my dropdownlist it will set the "costcenter" visibility to true.

so far this is what i have. is this the proper use of syntax for javascript?

function hideMe()
{
var g = document.getElementById('costcenterid');
var e = document.getElementById('dg_form_ctl02_DropDownList1');
if(e == 'computer')
{
g.style.display = 'block';
else
g.style.display = 'none';
}
}

C# code behind

ClientScript.RegisterStartupScript(GetType(),"hwa","hideMe();",true);

i found this code from somewhere, but i'm not sure what goes in the "hwa"

10
  • assuming SetVisible is valid, this looks like it should work Commented Aug 14, 2012 at 22:51
  • What do you mean by an object 'costCenter'? Is that an HTML element or something? Commented Aug 14, 2012 at 22:52
  • Okay, if i wanted to call this method with c# code how would it look like? Commented Aug 14, 2012 at 22:52
  • actually, check the answer I'm about to post Commented Aug 14, 2012 at 22:53
  • @hsalama the object 'costCenter' i think would be an html element. its part of a gridview row and the datasource is connected to sqlserver Commented Aug 14, 2012 at 22:54

2 Answers 2

1
document.getElementById("id").style.display="none|block"
Sign up to request clarification or add additional context in comments.

1 Comment

is there anything i need to put inside the "none|block"?
0

rather than .value, try this:

var selectedVar = document.getElementById("dg_form_ctl02_DropDownList1").options[e.selectedIndex].text;

As far as calling it from c# code, that depends on what kind of project this is. If it's winforms, do it from the codebehind. If it's mvc, I'd generally suggest not doing it at all.

1 Comment

hmm it is a website kind of project, but i had to use some code behind, okay. thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.