/    Sign up×
Community /Pin to ProfileBookmark

Dynamic addition of buttons

I want to add buttons, input fields, etc. in a dynamic way, through a call to a javascript function. I can’t do it in html because i don’t know up-front what buttons, text, etc. I would need. Any suggestions how to do it?
The follow up question would be similar, except for dynamic additions to a form.
I tried:

[code]document.write(…….)[/code]

but this seems to create a new document, which ignores the remaining portions of the html code.
Anyway, is it possible to have:

[code]document.write(‘<input type=”button” name=”testButton” value=”test” onClick=”alert(‘test OK’)”>’);[/code]

Thanks.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceJan 29.2006 — See the [URL=http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/appendchild.asp]appendChild()[/URL] and the [URL=http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/createelement.asp]createElement()[/URL] methods. A sample:
<i>
</i> var img = document.createElement("IMG");
img.className = "coins";
img.src = coinimages[idx];
img.alt = coinnames[idx];
img.title = coinnames[idx];
img.style.position = "absolute";
img.style.left = x+"px";
img.style.top = y+"px";
img.style.zIndex = "2";
img = purse.appendChild(img);
if (window.Event) {
img.onmousedown = function(event) { return setDrag(this, event); };
img.onmousemove = function(event) { return resetMove(event); };
img.onmouseup = function(event) { return endDrag(event); };
} else {
img.onmousedown = function() { return setDrag(this, event); };
img.onmousemove = function() { return resetMove(event); };
img.onmouseup = function() { return endDrag(event); };
}

Cheers.
Copy linkTweet thisAlerts:
@notageekauthorJan 29.2006 — Thanks. Looks like this is what I need. Time to do some tests.
×

Success!

Help @notageek spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...