473,809 Members | 2,733 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to wire click event with argument when create input

Hi,

I have the following function that works. It would create an input
that would invoke a click event that call a javascript function:

function createButton(te xt)
{
var btn = document.create Element('input' );
btn.type = 'submit';
btn.value = text;
btn.setAttribut e('onclick', 'execAction()') ; //this does not
work
btn.setAttribut e('class', 'CustomButton') ; //this does not
work
btn.onclick = execAction; //this works
return btn;
}

function execAction()
{
alert('in execAction');
return false;
}

The question is, if I have an execAction function with an argument,
how do I change the code in createButton to accomodate it?

Thanks in advance,
Quoc Linh

Jun 22 '07 #1
4 2797
On Jun 22, 12:10 am, quoclinh <lequocl...@yah oo.comwrote:
Hi,

I have the following function that works. It would create an input
that would invoke a click event that call a javascript function:

function createButton(te xt)
{
var btn = document.create Element('input' );
btn.type = 'submit';
btn.value = text;
btn.setAttribut e('onclick', 'execAction()') ; //this does not
work
btn.setAttribut e('class', 'CustomButton') ; //this does not
work
btn.onclick = execAction; //this works
return btn;

}

function execAction()
{
alert('in execAction');
return false;

}

The question is, if I have an execAction function with an argument,
how do I change the code in createButton to accomodate it?

Maybe try:

//....

btn.onclick = execAction;
btn.args = createButtonArg s;
return btn;

function execAction() {

this.args*2.141 59
// etc...
}

Jun 22 '07 #2
On Jun 22, 5:10 pm, quoclinh <lequocl...@yah oo.comwrote:
Hi,

I have the following function that works. It would create an input
that would invoke a click event that call a javascript function:
[...]
btn.onclick = execAction; //this works
[...]
>
The question is, if I have an execAction function with an argument,
how do I change the code in createButton to accomodate it?
btn.onclick = function() {
execAction(arg1 , arg2, ...);
}

Incidentally, if you want a function that fires when a form is
submitted, you are much better off to put it on the form's onsubmit
handler rather than the submit button's onclick handler.
--
Rob

Jun 22 '07 #3
Skye Shaw!@#$ wrote:
On Jun 22, 12:10 am, quoclinh <lequocl...@yah oo.comwrote:
>>Hi,

I have the following function that works. It would create an input
that would invoke a click event that call a javascript function:

function createButton(te xt)
{
var btn = document.create Element('input' );
btn.type = 'submit';
btn.value = text;
btn.setAttribut e('onclick', 'execAction()') ; //this does not
work
btn.setAttribut e('class', 'CustomButton') ;
btn.className=' CustomButton';
btn.onclick=exe cAction;

Mick
//this does not
>>work
btn.onclick = execAction; //this works
return btn;

}

function execAction()
{
alert('in execAction');
return false;

}

The question is, if I have an execAction function with an argument,
how do I change the code in createButton to accomodate it?

Maybe try:

//....

btn.onclick = execAction;
btn.args = createButtonArg s;
return btn;

function execAction() {

this.args*2.141 59
// etc...
}
Jun 22 '07 #4
On Jun 22, 1:56 am, RobG <r...@iinet.net .auwrote:
On Jun 22, 5:10 pm, quoclinh <lequocl...@yah oo.comwrote:
Hi,
I have the following function that works. It would create an input
that would invoke a click event that call a javascript function:
[...]
btn.onclick = execAction; //this works
[...]
The question is, if I have an execAction function with an argument,
how do I change the code in createButton to accomodate it?

btn.onclick = function() {
execAction(arg1 , arg2, ...);
}

Incidentally, if you want a function that fires when a form is
submitted, you are much better off to put it on the form's onsubmit
handler rather than the submit button's onclick handler.

--
Rob
Hi all,

Thank you for all your solutions! I really appreciate it. I chose to
go with RobG solution and it's work beautifully. However, being able
to pass the argument value dynamically instead of fixed value would be
tremendously useful as well. I will try other methods when time
allowed.

Thanks again for all your help!

Quoc Linh

Jun 26 '07 #5

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

Similar topics

2
6085
by: Csaba2000 | last post by:
I'd like to be able to simulate a mouse click on an arbitrary HTML element (for the purpose of invoking whatever behaviour that element would have, had a real mouse click come to it) so that my click event will contain mouse coordinates (I only need this for IE 5.5+) In most cases, if domElem is the element, I can do domElem.click and I get the desired behaviour (e.g. buttons) so I don't need the mouse coordinates. However, if I have an...
4
17260
by: Csaba2000 | last post by:
I want to be able to programatically click on the center of an <INPUT type=image ...> element (I only care about IE 5.5+). This should work regardless of whether IE has focus. Normally you would do myDomElement.click and the mouse doesn't matter, but in the case of an input image element, what happens is the submitted url has something like "?x=12&y=7" appended to it (the numbers vary per mouse position on the clicked element). If you hit...
8
2038
by: George Hester | last post by:
In a page I have when the user left-clicks the page a Input box for a form gets the focus. But if the user right-clicks the page the Input box is not getting the focus. I'd like the Input box to get the focus no matter where on the page the user clicks be it right-click or left-click. Right now there is no context menu when the user right-clicks. Do you think that's the problem? Any ideas how to get this right-click left-click Input box...
7
2519
by: MLH | last post by:
I tried the following code to prevent a checkbox from being updated (going from a value of Null to True, from True to False or from False to True). I was surprised it did not work. Can anyone offer a sensible, logical, insightful reason as to why Microsoft does not want to let programmers stop this event? Private Sub NoOwnerInfoChkBox_Click() If CurrentVehicleJobID = 0 Then
2
2694
by: Uninvisible | last post by:
I have put together a db for a law firm to keep track of counterfeit activities. There are four parent tables: tblContact tblTransaction tblAction tblFile I have created a form, frmNewMatter, for adding new records to the db. The form is based on tblFile and has a subform based on tblContact,
2
3715
by: Linda | last post by:
Hi, How do I dynamically add linkbuttons and wire them to same event? I am able to add linkbuttons but they do not fire the event. Does anybody have a working sample? Many thanks, Linda
3
36687
by: CodeRazor | last post by:
I am creating an aspx page using C# and would like to be able to dynamically create linkbuttons that all run the same fuction on the click event. However, I would like the function to accept a single argument (in this case the file name) to identify which button was clicked. I am using the Command event handler. The link buttons load correctly, but when i click on a link, the event handler code does not execute. Any ideas?
0
2962
by: Demetri | last post by:
I have created a web control that can be rendered as either a linkbutton or a button. It is a ConfirmButton control that allows a developer to force a user to confirm if they intended to click it such as when they do a delete. Everything is great. By and large it will be used in my repeater controls using the command event when the user clicks on it and so that event is working great. My issue is the Click event. When the control is...
2
2397
by: Chu | last post by:
Thanks everyone for taking a moment to read this. I've got a page where I use a LinkButton and I wire up a dynamic event to the button. When the user clicks the button, the event is fired as expected. In the event code for that button, a new LinkButton is added to the page and is wired up to yet a different event, however when clicked, the page is posted back but the event is not triggered. I'm assuming it has something to do with the...
0
9721
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
9601
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
10637
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
10376
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
7660
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
6881
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();...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
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
3
3014
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.