|
-
Oct 31st, 2012, 01:37 PM
#1
Thread Starter
PowerPoster
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,
-
Oct 31st, 2012, 06:25 PM
#2
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
-
Oct 31st, 2012, 07:26 PM
#3
Thread Starter
PowerPoster
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.
-
Nov 1st, 2012, 05:58 PM
#4
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".
-
Nov 1st, 2012, 09:24 PM
#5
Re: Javascript isn't being executed?
-
Nov 6th, 2012, 08:51 AM
#6
Re: Javascript isn't being executed?
yep "OnClientClick" is the correct command
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|