473,320 Members | 2,052 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.

Create input button with event

Hi,

I'd like to create an input button with a click event calling a
javascript function. pretty basic. I just can't figure out how to
wire the onclick event. this is what I have so far:

function createButton(text, clickEvent)
{
var btn = document.createElement('input');
btn.type = 'submit';
btn.value = text;
//How to code click event here?

//How to set default css class?

return btn;
}

Your help is much appreciated.

Quoc Linh

Jun 22 '07 #1
1 1570
quoclinh wrote:
Hi,

I'd like to create an input button with a click event calling a
javascript function. pretty basic. I just can't figure out how to
wire the onclick event. this is what I have so far:

function createButton(text, clickEvent)
{
var btn = document.createElement('input');
btn.type = 'submit';
btn.value = text;
//How to code click event here?

//How to set default css class?

return btn;
}

Your help is much appreciated.

Quoc Linh
Perhaps, something like this.
<HTML>

<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<TITLE>Test</TITLE>

<SCRIPT type="text/javascript">
function createButton(text)
{
var btn = document.createElement('input');
btn.setAttribute('type','submit');
btn.setAttribute('value',text);

var a = document.getElementById("test");

document.body.insertBefore( btn, a );
}

</SCRIPT>
</HEAD>

<BODY>
<A ID="test" HREF="#" ONCLICK="createButton('okay')">Click Me</A>
</BODY>
</HTML>

--

# WWW.LOUDHEART.COM
# classified ad + forum
# = a work in progress
Jun 22 '07 #2

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

Similar topics

2
by: Victor A. Cuya | last post by:
Hello all, I have been trying to solve an annoying behavior with PHP (I think). Maybe some of you have encountered the same and have some ideas. I have an html form and I use an <input...
1
by: Jawahar Rajan | last post by:
All, I am using a few Input type of "Image" instead of a classic submit button in a form to achieve various tasks for example image1 - add user image2 - modify user image3 - delete user...
3
by: Colin Graham | last post by:
Hi there, I am working on a project at the minute and i have created a button using the following code. <asp:button id="Button1" onclick="upload" runat="server" Width="119px"...
0
by: Anonieko | last post by:
Are there any javascript codes there? Answer: Yes On the PageLoad event call InitialClientControsl as follows /// <summary> /// This will add client-side event handlers for most of the...
2
by: sowmram | last post by:
Hi, I'm trying to create a site very similar to wiki, where you can edit, save.. Generally update data for the future use... This particular program I wanna do it using javascripts... Please...
5
by: The Devil | last post by:
Hi, This is not just a simple input form made with javascript. This is the code: <html><head> <script language="JavaScript"> var i=0; function add(inputEvent, inputDur, inputCode,...
11
by: cmdolcet69 | last post by:
I have the code below that will evaluate a string of characters. If its less then 12 long it will trigger a message box if its equal it will save the information and close the form. I have this...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
6
by: Omicron | last post by:
Hello, Can someone lead me in the right direct with this request: Please look at the piece of code below: <table summary="Sort Buttons"> <tr> <td> <input onclick="justSong_filter()"...
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...
1
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.