473,320 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

What is the problem with onClick ?

I have to execute a javascript function Test on Click event of a button.But the error is "Test is not identified as a function in the sourse file".Actually the exact function to be executed is YearValidation().But that function would work in the onFocus event but not with onClick.
Please help me.


<td colSpan="2"><asp:button id="btnReset" CssClass="Button" Runat="server" Text="Reset"></asp:button>&nbsp;
<asp:button id="btnSearch" CssClass="Button" OnFocus ="YearValidation()" OnClick="Test()" Runat="server" Text="Search"></asp:button></td>

Script function Defenition

function Test()
{
alert("Hi");

}

function YearValidation()
{
var yearTo=document.getElementById("ddlTo").value;
var yearFrom=document.getElementById("ddlYearRange").v alue;
if(yearTo<yearFrom)
{
alert("Error: Invalid year range selected. ");

}
}
Dec 5 '07 #1
2 867
radcaesar
759 Expert 512MB
I have to execute a javascript function Test on Click event of a button.But the error is "Test is not identified as a function in the sourse file".Actually the exact function to be executed is YearValidation().But that function would work in the onFocus event but not with onClick.
Please help me.


<td colSpan="2"><asp:button id="btnReset" CssClass="Button" Runat="server" Text="Reset"></asp:button>&nbsp;
<asp:button id="btnSearch" CssClass="Button" OnFocus ="YearValidation()" OnClick="Test()" Runat="server" Text="Search"></asp:button></td>

Script function Defenition

function Test()
{
alert("Hi");

}

function YearValidation()
{
var yearTo=document.getElementById("ddlTo").value;
var yearFrom=document.getElementById("ddlYearRange").v alue;
if(yearTo<yearFrom)
{
alert("Error: Invalid year range selected. ");

}
}
The functions should be inside the <script language="javascript">

Then when call use javascript: like

Onclick="javascript:Test()"
Dec 5 '07 #2
Plater
7,872 Expert 4TB
When you create the asp:button, onclick refers to a function in backend code.
If you want javascript function, use onclientclick
(Only applies to asp objects, not regular html objects)
Dec 5 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: pete | last post by:
I found it in the view source of a corporate website. <script Language="Javascript"> <!-- var keyMacro= ]; //--> </script>
3
by: Robert Dell | last post by:
I have a problem comparing strings in an order form i'm writing. I want to give a running total at the bottom of the page and it appears to be working except it doesn't compare correctly (it...
7
by: David. E. Goble | last post by:
Hi all; I have the following files; index.html, sigsheader.js, sigsboby.js, smilesbody.js and smiles.js. The sourse is below. The page displays two manual slide shows... Each slideshow has a set...
5
by: kai | last post by:
Hi, In ASP.NET , what is the difference between OnClick and Click events for a button? Because we have button click event, it can trigger events, why we still need OnClick? Please help. ...
7
by: amit | last post by:
Hello everybody, I need your advice on this. In my javascript I'm using two anchor <A> which both are to download a pdf file. That works fine but my question is why the "this" parameter in...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.