473,385 Members | 1,838 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,385 software developers and data experts.

Calling external function via button's onclick event...

I have always used VBScript but now need to convert my syntax to JavaScript.
In an external file, I have a function that is called when a user clicks a
button on a login page. The function checks the format of data that has
been entered by the user and makes sure that all required fields have been
filled out. On the login page, between the <head></headtags I have the
following syntax:

<script language="javascript" src="scripts/login.js"></script>

The syntax on the button is as follows:

<input type="button" name="cbSubmit" value="Login"
onClick="javascript:validateentry" tabindex="4" style="cursor:hand;">

When I load the page and click the button, I get the following error
message:

Error: 'validateentry' is undefined

I am a JavaScript newbie and already am at a loss to see what the problem
is! I have checked the obvious and can confirm that the function name and
case is correct and matches in both the JS file and the web page. I'm sure
it's something really simple, but I just can't see it!!

Can anyone help me?!

Debbie :(
Aug 15 '07 #1
2 5328
Debbie wrote:
I have always used VBScript but now need to convert my syntax to JavaScript.
Probably Microsoft JScript.
In an external file, I have a function that is called when a user clicks a
button on a login page. The function checks the format of data that has
been entered by the user and makes sure that all required fields have been
filled out. On the login page, between the <head></headtags
= within the `head' element.
I have the following syntax:

<script language="javascript" src="scripts/login.js"></script>
Remove the deprecated `language' attribute, add the required `type'
attribute with value "text/javascript".
The syntax on the button is as follows:

<input type="button" name="cbSubmit" value="Login"
onClick="javascript:validateentry" tabindex="4" style="cursor:hand;">
`cb' is a prefix I reserve for CheckBoxes, `bt' for BuTtons; however, I
don't think this `input' element needs a name.

Remove `javascript:'. Replace the proprietary `hand' with the standards
compliant `pointer' value.
When I load the page and click the button, I get the following error
message:

Error: 'validateentry' is undefined
Maybe that is because of the missing `type' attribute. Another, more likely
possibility is that you have not used the same character case as in the
method declaration. J(ava)Script/ECMAScript identifiers are case-sensitive,
VBScript probably is not (as VBA is not).

Furthermore, as functions/methods are first-class objects (Function objects)
in ECMAScript implementations, and the identifier is a reference to that
object, using the identifier alone is not enough to call a function/method
as it probably is in VBScript. You have to append a (here empty) parameter
list, sometimes called "the call operator":

validateEntry()
HTH

PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Aug 15 '07 #2
Thomas 'PointedEars' Lahn said the following on 8/15/2007 2:13 PM:
Debbie wrote:
>I have always used VBScript but now need to convert my syntax to JavaScript.

Probably Microsoft JScript.
You have a vivid imagination sometimes.
>In an external file, I have a function that is called when a user clicks a
button on a login page. The function checks the format of data that has
been entered by the user and makes sure that all required fields have been
filled out. On the login page, between the <head></headtags

= within the `head' element.
Irrelevant.
>I have the following syntax:

<script language="javascript" src="scripts/login.js"></script>

Remove the deprecated `language' attribute, add the required `type'
attribute with value "text/javascript".
And use an attribute whose only value is obsolete.
>The syntax on the button is as follows:

<input type="button" name="cbSubmit" value="Login"
onClick="javascript:validateentry" tabindex="4" style="cursor:hand;">

`cb' is a prefix I reserve for CheckBoxes, `bt' for BuTtons; however, I
don't think this `input' element needs a name.
What you reserve prefixes for is irrelevant.
Remove `javascript:'. Replace the proprietary `hand' with the standards
compliant `pointer' value.
Totally irrelevant to anything about JS.
>When I load the page and click the button, I get the following error
message:

Error: 'validateentry' is undefined

Maybe that is because of the missing `type' attribute.
Monkeys ass and you know it.
Another, more likely possibility is that you have not used the same character
case as in the method declaration.
More monkeys ass and you know it.
Furthermore, as functions/methods are first-class objects (Function objects)
in ECMAScript implementations, and the identifier is a reference to that
object, using the identifier alone is not enough to call a function/method
as it probably is in VBScript. You have to append a (here empty) parameter
list, sometimes called "the call operator":

validateEntry()
And you only had to babble about irrelevant things for a few minutes
until you pointed out the problem.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Christian Radermacher | last post by:
Hi, the following code has the mentioned behaviour: <html> <head> <script type="text/javascript"> function newA() { for (i=0;i<3;i++) { var a = window.frames.document.createElement("a");
3
by: Curtis | last post by:
Sorry if this is the wrong newsgroup in which to post. We have an asp page on a webserver supporting asp pages. How can we run/call a function on this page using an onclick or other event from...
1
by: Steven | last post by:
Hello, I have a Javascript function which will get executed only when I click a Image Button on my aspx page (code behind - C#). C# InImgBut on click function --> {...
4
by: Ryan Ternier | last post by:
I have a button event: Public Sub SwitchItem(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim btnTest As New Button Dim astrTest As String() btnTest = CType(sender, Button)...
1
by: Mphoza | last post by:
Hi! Programmers,,,,,, Scenario I have a DataGrid with the delete button, If the user delete the row I'd like to show a confirmation dialog box with two buttons(Yes,No). If the user click yes...
14
by: Paul | last post by:
Hi I have 2 functions in java script, one opens a second window-this works, the other is supposed to close this second window, does not seem to be working. Just wondering if anyone had any ideas....
5
by: Simon Harris | last post by:
Hi All, I am trying to call a method in a web form, from an event fired in a user control. My user control displays a map, which has a link button to enlarge/shrink the map. When the user...
3
by: phish.guy | last post by:
How do I call another event's onclick function from a button press? I have stored information dynamically created in a div onclick function that is not accessible directly by the button, but i...
5
by: Stinky Pete | last post by:
Hi (again) ;-) I'm still very much at the bottom of a steep learning curve with VB, so any and all help is always appreciated. I've found some code to generate the user names who have logged...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.