Results 1 to 6 of 6

Thread: Javascript isn't being executed?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    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,
    Blake

  2. #2
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    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
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    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.
    Blake

  4. #4
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    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".
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Javascript isn't being executed?

    Thread moved.

  6. #6
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    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
  •  



Click Here to Expand Forum to Full Width