5 Replies - 505 Views - Last Post: 28 February 2018 - 12:30 PM

#1 ikhlas06   User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 328
  • Joined: 20-May 16

onchange() does not run. any idea how can i call javascript function w

Posted 28 February 2018 - 11:27 AM

onchange() does not run. any idea how can i call javascript function without refreshing or going on server side?


<script type="text/javascript">
    function ddl_changed() {
            alert("test");
        }
    </script>


    <asp:DropDownList ID="MonthDD"  runat="server" onchange="ddl_changed()">
            <asp:ListItem>Month</asp:ListItem>
            <asp:ListItem>Jan</asp:ListItem>
            <asp:ListItem>Feb</asp:ListItem>
            <asp:ListItem>Mar</asp:ListItem>
            <asp:ListItem>Apr</asp:ListItem>
            <asp:ListItem>May</asp:ListItem>
            <asp:ListItem>Jun</asp:ListItem>
            <asp:ListItem>Jul</asp:ListItem>
            <asp:ListItem>Aug</asp:ListItem>
            <asp:ListItem>Sep</asp:ListItem>
            <asp:ListItem>Oct</asp:ListItem>
            <asp:ListItem>Nov</asp:ListItem>
            <asp:ListItem>Dec</asp:ListItem>
        </asp:DropDownList>


Is This A Good Question/Topic? 0
  • +

Replies To: onchange() does not run. any idea how can i call javascript function w

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,173
  • Joined: 12-June 08

Re: onchange() does not run. any idea how can i call javascript function w

Posted 28 February 2018 - 11:43 AM

Works fine with me. Since I don't see your complete code I am assuming you have your dropdownlist in a body and form tags while your javascript is in the head?

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default14.aspx.vb" Inherits="Default14" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">

        function ddl_changed()
        {
            alert("test");
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">

        <asp:DropDownList ID="MonthDD" runat="server" onchange="ddl_changed()">
            <asp:ListItem>Month</asp:ListItem>
            <asp:ListItem>Jan</asp:ListItem>
            <asp:ListItem>Feb</asp:ListItem>
            <asp:ListItem>Mar</asp:ListItem>
        </asp:DropDownList>
    </form>
</body>
</html>

Was This Post Helpful? 1
  • +
  • -

#3 ikhlas06   User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 328
  • Joined: 20-May 16

Re: onchange() does not run. any idea how can i call javascript function w

Posted 28 February 2018 - 11:48 AM

werid i gett error: Javascript runtime error: 'ddl_changed' is undefined
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,173
  • Joined: 12-June 08

Re: onchange() does not run. any idea how can i call javascript function w

Posted 28 February 2018 - 11:50 AM

It'll be a mystery until folk can see what/how you are implementing as a whole.
Was This Post Helpful? 0
  • +
  • -

#5 ikhlas06   User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 328
  • Joined: 20-May 16

Re: onchange() does not run. any idea how can i call javascript function w

Posted 28 February 2018 - 12:07 PM

<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %>

<!DOCTYPE html>
<html lang="en">
<head id="Head1" runat="server">
    <!-- my css -->
    <link rel="stylesheet" type="text/css" href="/test/Styles/MasterPage.css" />

     <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
		<asp:ContentPlaceHolder id="ContentPH_main" runat="server">
		</asp:ContentPlaceHolder>
    </form>
</body>
</html>





<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test2.aspx.vb" MasterPageFile="~/MasterPage.master" Inherits="UI_test2"  %>
<asp:Content id="Home_Content1" ContentPlaceHolderID="head" runat="server">

	<%-- Override Css code --%>
	<style type="text/css">
		function ddl_changed()
            alert("test");
        }
	</style>

</asp:Content>

<asp:Content id="Home_Content2" ContentPlaceHolderID="ContentPH_main" runat="server">
	<asp:DropDownList ID="MonthDD" runat="server" onchange="ddl_changed()">
		<asp:ListItem>Month</asp:ListItem>
		<asp:ListItem>Jan</asp:ListItem>
		<asp:ListItem>Feb</asp:ListItem>
		<asp:ListItem>Mar</asp:ListItem>
	</asp:DropDownList>
</asp:Content>

Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,173
  • Joined: 12-June 08

Re: onchange() does not run. any idea how can i call javascript function w

Posted 28 February 2018 - 12:30 PM

Why would you have two content areas? Stick to one.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1