javascript trouble

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>
 
A

Alexey Smirnov

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();"
 
M

Martin Honnen

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');
 
H

Hans Kesting

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
 
A

Alexey Smirnov

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top