I'm working with ASP.NET 2.0 and Javascript. I started out OK by attaching the JS code to the object in the PageLoad(). Note that rbInputStyle is a RadioButtonList .
rbInputStyle.It ems(0).Attribut es.Add("onclick ", lblPrice.Client ID
+ ".innerHTML=""U nit Price"";")
rbInputStyle.It ems(1).Attribut es.Add("onclick ", lblPrice.Client ID
+ ".innerHTML=""T otal Proceeds"";")
That worked great. Now I need to move the javascript into a seperate external file, since it needs to get a bit more involved and I would like to reuse it. I tried the following:
rbInputStyle.It ems(0).Attribut es.Add("onclick ", "ShowPrice( " + lblPrice.Client ID
+ ");")
rbInputStyle.It ems(1).Attribut es.Add("onclick ", "ShowProcee ds(" +
lblPrice.Client ID + ");")
In the aspx source file I added the following:
<script language="JavaS cript" src="MyJSLib.js "></script>
Finally, in MyJSLib.js I created two functions:
function showPrice(lbl)
{
lbl.innerHTML=" Unit Price";
}
function showProceeds(lb l)
{
lbl.innerHTML=" Total Proceeds";
}
This is where it breaks down. I can't seem to get the above code to work. If I can get past this, I should have no problems passing in the multiple controls.
rbInputStyle.It ems(0).Attribut es.Add("onclick ", lblPrice.Client ID
+ ".innerHTML=""U nit Price"";")
rbInputStyle.It ems(1).Attribut es.Add("onclick ", lblPrice.Client ID
+ ".innerHTML=""T otal Proceeds"";")
That worked great. Now I need to move the javascript into a seperate external file, since it needs to get a bit more involved and I would like to reuse it. I tried the following:
rbInputStyle.It ems(0).Attribut es.Add("onclick ", "ShowPrice( " + lblPrice.Client ID
+ ");")
rbInputStyle.It ems(1).Attribut es.Add("onclick ", "ShowProcee ds(" +
lblPrice.Client ID + ");")
In the aspx source file I added the following:
<script language="JavaS cript" src="MyJSLib.js "></script>
Finally, in MyJSLib.js I created two functions:
function showPrice(lbl)
{
lbl.innerHTML=" Unit Price";
}
function showProceeds(lb l)
{
lbl.innerHTML=" Total Proceeds";
}
This is where it breaks down. I can't seem to get the above code to work. If I can get past this, I should have no problems passing in the multiple controls.
Comment