By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,608 Members | 1,940 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,608 IT Pros & Developers. It's quick & easy.

Create input button with event

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.