473,698 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

giving buttons the same onclick event

Hi,
I'm mocking up an interface in javascript for an HCI assignment. I want
to be able to make the default onclick event for the buttons on my page
to display an alert since the buttons won't work yet. Is there an easy
way to do this? and it has to be as easy as giving each button their
own onclick attribute otherwise I'll just do that.

Oct 3 '05 #1
10 1884
> and it has to be as easy as giving each button their
own onclick attribute otherwise I'll just do that.


Yes just do that !

onclick = "event()"
Oct 3 '05 #2
drawde83 wrote:
Hi,
I'm mocking up an interface in javascript for an HCI assignment. I want
to be able to make the default onclick event for the buttons on my page
to display an alert since the buttons won't work yet. Is there an easy
way to do this? and it has to be as easy as giving each button their
own onclick attribute otherwise I'll just do that.


Well, making it the default behavior is not too hard.
<html><head>
<script type="text/javascript" language="javas cript1.2">
<!--
function myClick(oI)
{
alert("Under Construction " +oI.name)
}
function captureInputs()
{
aINPUTcollectio n=self.document .getElementsByT agName("input")
for(x=0;x<aINPU Tcollection.len gth;x++)
{
oI=aINPUTcollec tion[x]
if(oI.type="but ton")if(!oI.onc lick);
oI.onclick=new Function("retur n myClick(this)")
}
}
// -->
</script>
<body onload="capture Inputs()">
<form name="foo">
<input type="button" name="foo1" value="foo1">
<input type="button" name="foo2" value="foo2">
<input type="button" name="foo3" value="foo2"
onclick="return false">
</form>
</body>
</html>
--
--.
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML, CSS,Javascript
--=<> Internet Programming since 1994 <>=-- DHTML NSAPI TCP/IP
--=<> http://resume.drclue.net <>=-- AJAX, SOAP, XML, HTTP
--=<> http://www.drclue.net <>=-- SERVLETS,TCP/IP, SQL
--.
Oct 3 '05 #3
Lee
Dr Clue said:

drawde83 wrote:
Hi,
I'm mocking up an interface in javascript for an HCI assignment. I want
to be able to make the default onclick event for the buttons on my page
to display an alert since the buttons won't work yet. Is there an easy
way to do this? and it has to be as easy as giving each button their
own onclick attribute otherwise I'll just do that.


Well, making it the default behavior is not too hard.
<html><head>
<script type="text/javascript" language="javas cript1.2">
<!--
function myClick(oI)
{
alert("Under Construction " +oI.name)
}
function captureInputs()
{
aINPUTcollectio n=self.document .getElementsByT agName("input")
for(x=0;x<aINPU Tcollection.len gth;x++)
{
oI=aINPUTcollec tion[x]
if(oI.type="but ton")if(!oI.onc lick);
oI.onclick=new Function("retur n myClick(this)")
}
}
// -->
</script>
<body onload="capture Inputs()">
<form name="foo">
<input type="button" name="foo1" value="foo1">
<input type="button" name="foo2" value="foo2">
<input type="button" name="foo3" value="foo2"
onclick="return false">
</form>
</body>
</html>


1. Please don't encourage people to use the <-- //--> comments in script.
2. Wouldn't it be better to use a decent text editor and replace each occurance
of /<input type="button"/ with /<input type="button" onclick="notyet ()"/ ?

Oct 3 '05 #4
Lee wrote:
<snip>
1. Please don't encourage people to use the <-- //--> comments in script.
Old habits die real hard. Probably the only thing that would stop my
fingers from automaticly typing that line without me even thinking about
it would be if it stopped working.
2. Wouldn't it be better to use a decent text editor and replace each occurance
of /<input type="button"/ with /<input type="button" onclick="notyet ()"/ ?


This is a javascript newsgroup, so I give a javascript solution,
and besides it's a much more useful response in the long run.
--
--.
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML, CSS,Javascript
--=<> Internet Programming since 1994 <>=-- DHTML NSAPI TCP/IP
--=<> http://resume.drclue.net <>=-- AJAX, SOAP, XML, HTTP
--=<> http://www.drclue.net <>=-- SERVLETS,TCP/IP, SQL
--.
Oct 3 '05 #5
Dr Clue wrote:
<snip>
<html><head>
<script type="text/javascript" language="javas cript1.2">
Encouraging browsers that will to use the divergent type-converting and
assignment behaviour unique to JavaScript 1.2 is a very bad idea.
<!--
The 'hide from older browsers' HTML-style comments are now redundant,
and a bad habit to encourage in others who may eventually be asked to
script XHTML, where they are potentially fatal.
function myClick(oI)
{
alert("Under Construction " +oI.name)
}
function captureInputs()
{
aINPUTcollectio n=self.document .getElementsByT agName("input")
for(x=0;x<aINPU Tcollection.len gth;x++)
{
oI=aINPUTcollec tion[x]
There does no appear to be any reason for using global variables for -
aINPUTcollectio n -, - x - or - oI -. This is a particularly dangerous
habit when it comes to loop counters, but still dubious otherwise. They
should all be function local variables. The general programming axiom
that variables should never be given more scope than is absolutely
necessary should be observed as rigorously in javascript as any other
language.
if(oI.type="but ton")if(!oI.onc lick);
oI.onclick=new Function("retur n myClick(this)")

<snip>

It is really chunky and inefficient to be creating a new function object
for each button when you could just defined - myClick - as:-

function myClick(){
alert('Under Construction '+this.name);
}

- and assign references to that one function object to each button
element's - onclick - handler as:-

oI.onclick = myClick;

Richard.
Oct 3 '05 #6
Dr Clue <ia*********@mi ndspring.com> wrote in message news:Xn******** *********@newsr ead1.news.pas.e arthlink.net...
drawde83 wrote:
Hi,
I'm mocking up an interface in javascript for an HCI assignment. I want
to be able to make the default onclick event for the buttons on my page
to display an alert since the buttons won't work yet. Is there an easy
way to do this? and it has to be as easy as giving each button their
own onclick attribute otherwise I'll just do that.
Well, making it the default behavior is not too hard.


The hard part is convincing the lecturer that you wrote it yourself; that's assuming that they're still bothering to ask
these days.
--
S.C.
Oct 4 '05 #7
Stephen Chalmers wrote:
Dr Clue <ia*********@mi ndspring.com> wrote in message news:Xn******** *********@newsr ead1.news.pas.e arthlink.net...
drawde83 wrote:
I'm mocking up an interface in javascript for an HCI assignment. I want
to be able to make the default onclick event for the buttons on my page
to display an alert since the buttons won't work yet. Is there an easy
way to do this? and it has to be as easy as giving each button their
own onclick attribute otherwise I'll just do that.

Well, making it the default behavior is not too hard.


The hard part is convincing the lecturer that you wrote it yourself; that's assuming that they're still bothering to ask
these days.


These days I think the concern ends with the cashing of the tuition
check, and that from there on your plugging up a seat that could be sold
again.

--
--.
--=<> Dr. Clue (A.K.A. Ian A. Storms) <>=-- C++,HTML, CSS,Javascript
--=<> Internet Programming since 1994 <>=-- DHTML NSAPI TCP/IP
--=<> http://resume.drclue.net <>=-- AJAX, SOAP, XML, HTTP
--=<> http://www.drclue.net <>=-- SERVLETS,TCP/IP, SQL
--.
Oct 4 '05 #8

Lee wrote:
Dr Clue said:

1. Please don't encourage people to use the <-- //--> comments in script.

Why is that? I'm just a dabbler in javascript and sometimes use it as
comments. What's wrong with doing it?

Oct 5 '05 #9
Lee
wo******@gmail. com said:


Lee wrote:
Dr Clue said:

1. Please don't encourage people to use the <-- //--> comments in script.

Why is that? I'm just a dabbler in javascript and sometimes use it as
comments. What's wrong with doing it?


If you're adding comments to your script, use the // syntax.
The SGML comment characters are not really part of Javascript.
If you use them to "hide code from old browsers", you're wasting
your time, because the percentage of such old browsers on the
internet dropped below 0.000 several years ago.

Oct 5 '05 #10

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

Similar topics

6
5186
by: amith | last post by:
hi, i have some 10 radio buttons meant to take the rating from the user. ex: 1 2 3 4 5 6 7 8 9 10 looks O O O O O O O O O O 1 2 3 4 5 6 7 8 9 10 features O O O O O O O O O O
6
3859
by: Jon | last post by:
Hello, I have a datagrid and the data in it is dynamically created at runtime... For iCounter = 0 To dataset.Tables(0).Columns.Count - 1 Dim objbc As New BoundColumn() With objbc .DataField = dsAllPastReplies.Tables(0).Columns(iCounter).ColumnName .HeaderText = dsAllPastReplies.Tables(0).Columns(iCounter).ColumnName If .DataField = dsAllPastReplies.Tables(0).Columns("ReplyID").ColumnName Then
4
4131
by: actionwoman63 | last post by:
Dear all I need to be able to check which one out of two submit buttons within the same form was pressed in a javascript function prior to form submission. And before I get flamed for not finding the answer in previous posts - I have already seen this question answered numerous times in this forum, only problem is that the recommended method is not available to me :-(. I know that if I could code an onclick event on the <input...
1
3334
by: Hrvoje Vrbanc | last post by:
Hello all! My question is the following: I add buttons (server controls) programatically into a table cell. Example: Dim btObnovi As Button = New Button() celija25.Controls.Add(btObnovi) The number of rows in the table depends on number of records in a database. Therefore, the number of buttons is variable.
1
8844
by: Jerry | last post by:
We have a 10-question quiz for kids, each question being a yes or no answer using radio selections. I'd like to keep a current total of yes's and no's at the bottom of the quiz (if the user selects yes to question 1, the total of yes's increases by 1). I've been searching for a while but I'm not sure I'm searching with the right keywords. Can anyone direct me to a source I can review to learn how to do this? Thanks! --
5
2454
by: mayur_hirpara | last post by:
Hi, I have been developing web applications for a while now. However, as I was thinking through the architecture I really don't understand the "How server can identify between which buttons has made the postback request.???" for e.g. I have a webpage default.aspx. I place TWO or more server buttons on it. Create server-side event handlers for each of the buttons.
6
1591
by: Totto | last post by:
Hi, Anyone know the best solution to dynamically add buttons to a asp 2.0 page using data from Sql server? Are there any contols suitable for this or is it best to iterate the dataset and dynamicaly add buttons in the asp page? Totto
2
1335
by: Ian :\) | last post by:
Hi Just learning JavaScript and I'm trying to reference radio buttons generated by php, the relevant lines are: <td width="9%" align="center" class="bg-tb-td"><input name="editArticle" type="radio" value=" <?php echo $row_rsArticles; ?>" onclick = "document.form1.deleteArticle.checked='false')"/></td> <td width="9%" align="center" class="bg-tb-td"><input
3
1126
by: COHENMARVIN | last post by:
I created asp.net pages that contained several controls, including buttons. I would double click on the button, and this would take me to the 'code-behind' page, and create the shell of a routine to handle that button click. What I found later though, was that this routine was being executed twice. So I looked into it, and I found that the button had a 'onclick' attribute which was pointing to the routine, but also, the routine had a...
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.