javascript trouble

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

hi

asp.net 2.0

Here is the markup of a webpage I'm having trouble with. The trouble is that
nothing happens when I click on that button (<input id="Button1).

Any ideas what I do wrong here?

<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="CalendarControl.ascx.cs" Inherits="Controls_CalendarControl" %>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<input id="Button1" type="button" value="..." onclick="OnClick" /><br />

<div id="divCalendar" runat="server" style="display:none;
position:absolute;">
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
</div>


<script type="text/javascript" >
function OnClick()
{
if (divCalendar.style.display == "none")
divCalendar.style.display = "";
else
divCalendar.style.display = "none";
}
</script>
 
hi

asp.net 2.0

Here is the markup of a webpage I'm having trouble with. The trouble is that
nothing happens when I click on that button (<input id="Button1).

Any ideas what I do wrong here?

<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="CalendarControl.ascx.cs" Inherits="Controls_CalendarControl" %>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<input id="Button1" type="button" value="..." onclick="OnClick" /><br />

<div id="divCalendar" runat="server" style="display:none;
position:absolute;">
    <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
</div>

<script type="text/javascript" >
function OnClick()
{
    if (divCalendar.style.display == "none")
        divCalendar.style.display = "";
    else
        divCalendar.style.display = "none";}

</script>

Try onclick="javascript:OnClick();"
 
Jeff said:
<input id="Button1" type="button" value="..." onclick="OnClick" /><br />

With client-side scripting the event handlers take script code, not
simply names of methods. So you want to call the function named
'OnClick' and the proper function call syntax in JavaScript is
OnClick()
and not
OnClick.
So try
<div id="divCalendar" runat="server" style="display:none;
position:absolute;">
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
</div>


<script type="text/javascript" >
function OnClick()
{
if (divCalendar.style.display == "none")

I wouldn't rely on browsers like IE expose elements by there id but
instead use the W3C document.getElementById method e.g.
var cal = document.getElementById('divCalendar');
 
Try onclick="javascript:OnClick();"

The (client side) onclick argument always contains javascript, so you
don't have to prefix the code with "javascript:".

Hans Kesting
 
The (client side) onclick argument always contains javascript, so you
don't have to prefix the code with "javascript:".

Hans Kesting

I agree... the problem is of course in trailing brackets
 
Back
Top