Skip to main content
gamedev.net
🔒 Locked

[web] adding HTML with javascript

Started by boolean Dec 13, 2005 at 9:55 PM 3 replies 600+ views
Original Post
boolean
boolean
I have a quick question which has caused me to waste this entire day trying to do something so stupidly simple it makes me want to impale myself on a rusty pitchfork. I have a function that is called every time I press a button. The function adds a text field to a div tag. After adding it I want to insert the HTML tag < BR>, so that the next field that gets added is on a new line. I can't figure it out how to tell the &#106avascript to write this. Any ideas? This has been a bad week. Based on some code another member donated to me

var num = [0];

function add()
{
	var txt = document.createElement("input");

	txt.setAttribute("type", "text");
	txt.setAttribute("size", "[40]");
	txt.id = "spotlight_images" + num;
	txt.name = "spotlight_images" + num;
	txt.value = txt.id;
	
	document.getElementById('spotlight_images').appendChild(txt);
	num++;
	}


Colin Jeanne
Colin Jeanne
Off the top of my head, I think this should work

var br = document.createElement('br');document.getElementById('spotlight_images').appendChild(br);


I'm pretty sure you've tried that, but if not, I hope it works [smile]
boolean
boolean
oh happy days! THANKYOU GOOD SIR!

ARGH! I never heard of the command appendChild [sad]
Sander
Sander
Quote:
Original post by boolean
ARGH! I never heard of the command appendChild [sad]


Well, you used that command yourself to add the text fiels. That'll teach you to use someone else's code without understanding what it does [grin]

Colin Jeanne
Colin Jeanne
Quote:
Original post by Sander
Quote:
Original post by boolean
ARGH! I never heard of the command appendChild [sad]


Well, you used that command yourself to add the text fiels. That'll teach you to use someone else's code without understanding what it does [grin]

[grin]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.