...

View Full Version : how would i find HTML and add to it



Uchiha Sasuke
01-04-2004, 07:46 AM
yes, what would use to find HTML and add to it
i know how to find text, with this
document.getElementsByTagName('TD')[2].innerHTML.match(/ text blah/i)

but that only finds text with in coding, i need something that will search for a </textarea> and add scripting after the sepcific tag
thank you

swmr
01-04-2004, 11:11 AM
- not sure exactly what you had in mind, but this might be useful:



<html><head>
<title>-</title>
<script type="text/JavaScript">

function insertNode(){var btn, txt, elm;

btn = document.getElementsByTagName("button")[0];

elm = document.createElement("LABEL");

txt = document.createTextNode("label text");

document.body.insertBefore(elm, btn.nextSibling);

elm.appendChild(txt);
}
</script></head>
<body>
<button onclick="insertNode()">test</button>
</body>
</html>

Uchiha Sasuke
01-04-2004, 09:43 PM
well, actually, i just wanted to add like a table, and text with it for like announcements and important threads
how would i do that?
and the exact place it needs to find is this
<textarea name="message" rows="12" cols="60" wrap="soft" ONCLICK="javascript:storeCaret(this);" ONKEYUP="javascript:storeCaret(this);" ONCHANGE="javascript:storeCaret(this);" tabindex="3"></textarea>

and have it add a table and text after that </textarea>
how would that be done?
thanks for the reply

swmr
01-04-2004, 10:00 PM
how would that be done?

Pretty much just as in the example above: use the index of your textarea (instead of a button), and insert a table (instead of a label)...

Uchiha Sasuke
01-04-2004, 10:21 PM
well, i tried this, but it didn't work (keep in mind i have no clue what i'm doing)

<script type="text/JavaScript">

function insertNode(){var btn, txt, elm;

btn = document.getElementsByTagName("textarea")[0];

elm = document.createElement("blah blah");

txt = document.createTextNode("label text");

document.body.insertBefore(elm, btn.nextSibling);

elm.appendChild(txt);
}
</script>

swmr
01-04-2004, 11:28 PM
try this:



<html>
<head>
<title>-</title>
<script>
function insertNode(){var tgt, tbl, tbd, tr, td, txt;

tgt = document.getElementsByTagName("button")[0];

tbl = document.createElement("TABLE");
tbd = document.createElement("TBODY");
tr = document.createElement("TR");
td = document.createElement("TD");
txt = document.createTextNode("cell text");

td.appendChild(txt);
tr.appendChild(td);
tbd.appendChild(tr);
tbl.appendChild(tbd);

document.body.insertBefore(tbl, tgt.nextSibling);
}
</script>
</head>
<body><button onclick="insertNode()">test</button>
</body>
</html>


this tutorial (http://webreference.com/js/column44/index.html) might help, also...

Uchiha Sasuke
01-04-2004, 11:54 PM
that didn't really work either, sorry for all the trouble

see, this is exactly what i'm trying to do
have something find this exact HTML

<textarea name="message" rows="12" cols="60" wrap="soft" ONCLICK="javascript:storeCaret(this);" ONKEYUP="javascript:storeCaret(this);" ONCHANGE="javascript:storeCaret(this);" tabindex="3"></textarea>

and what i want added after it is this

<table border="0" cellspacing="1" cellpadding="0" align="center" width="70%" class="bordercolor"><tr class="catbg"><td align="center"><font color="990000"><b>Important Messages</b></FONT></TD><tr class="windowbg"><td><center>todays announcements!</center></td></tr></table>

now if you need more of an idea of the layout of the section i'm altering, this is what it looks like
i want a table of the right hand side of the posting area on this board
http://tester4.proboards22.com/index.cgi?board=testing&action=post

swmr
01-05-2004, 12:11 AM
that didn't really work either...

The example works just fine for me.

Whether it is tailored specifically to your needs is something for you to work out. ;)

Just take it one step at a time: do some research, test some methods, and act upon your observations.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum