Creating Dynamic DOM Elements

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
MikeEller
Forum Newbie
Posts: 11
Joined: Sun Feb 05, 2006 3:43 pm

Creating Dynamic DOM Elements

Post by MikeEller »

Hello,

I would like to be able to dynamically create HTML elements (text boxes, labels, buttons, etc) using DOM. Can this be done?
I know that I can create the entire page from scratch using DOMDocument, but I just want to insert elements by creating php objects that implement DOM elements.

For example, if I am in an page, lets say test.php, I want to, in php code, create a textbox. So I need to get a reference to the document (would this be $_SERVER['PHP_SELF']??? and then call createElement('input').

Code: Select all

 
$doc = $_SERVER['PHP_SELF'];
$doc.createElement('input');
 
I want to insert these elements as php objects that create DOM elements.
I need to do this to standardize some things in my environment.

Can anyone point me in the right direction?

Thank You,
Mike
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: Creating Dynamic DOM Elements

Post by kaszu »

User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Creating Dynamic DOM Elements

Post by Darhazer »

$_SERVER['PHP_SELF'] is not a DomElement.

The PHP itself is not DOM, so unless you do not create a DOMDocument, there won't be any object you can attach an element to.
If you want to create DOM elements in the HTML you've outputting, that you most likely need JavaScript's DOM functions. Otherwise, you can load an HTML in DOMDocument and create the input.
Post Reply