Javascript isn't being executed?
I have a web application developed in VS 2008. On a form, I have a <select> control that looks like this:
Code:
<select id="lstreports" class="width_280" size="1" name="lstreports" onserverclick="DisablePrintSchedule()" runat="server">
When make a selection from this control, the script DisablePrintSchedule() should fire but it doesn't. Below is my Javascript.
Code:
<script type="text/javascript">
function DisablePrintSchedule(){
alert('Made it here!');
var btn = document.getElementById('btnPrintSchedule');
alert('Made it here too!');
if (btn.attributes("SelectedIndex") == 2){
alert('Print Schedule!');
}
else {
alert('Don\'t Print!');
}
}
</script>
The first Alert isn't even executing. Is there anything I need to do in the code behind like Register the script?
Thanks,
Re: Javascript isn't being executed?
You're using "onserverclick" when you want "onclick". "onserverclick" is for server-side code, while "onclick" is for the client-side JavaScript.
Also, I would recommend not using alert() statements for debugging. console.log() is much nicer :)
Re: Javascript isn't being executed?
Already tried that and it didn't work but I figured it out anyway.
Thanks for your input though.
Re: Javascript isn't being executed?
This probably should have been in the ASP.NET forum. On second thoughts, it should have been "onclientclick" if the tag is being processed server-side with runat="server".
Re: Javascript isn't being executed?
Re: Javascript isn't being executed?
yep "OnClientClick" is the correct command