View Full Version : Adding Text To A Textarea
Shane B
03-03-2006, 01:23 AM
well ive been to just about every site there is for help with this and they all talk to me like im an idoit but never answer my question ... weird :\
anyways heres the deal ... ive been using this addText script(code below) to add predefined text to my textareas but all of the sudden it just stopped working and started giving me this JavaScript Error(code below).
addText Function:
function addText(ae,ab,ac){
var ad = ac;
document.ae.ab.text += ad;
}
JavaScript Error:
Line:41
Char:3
Code:0
Error:'document.ae.ab' is null or not an object
URL:http://zickin.com/?module=register
ive tried just about everything and im at a loss ... i really hope someone here can help me out cause this killing me.
greasonwolfe
03-03-2006, 02:02 AM
My first suggestion would be to post more of the code. I am guilty of this at times as well. However, in this instance, it is pretty much impossible for anyone to help you.
You are passing three values (ae, ab and ac) into the function but with what you posted nobody here knows what those three values are so rooting out the error you are recieving becomes a guessing game. Try to post more of the relevant code, particularly where you are making the function call so that we can see a sample of the values being passed into the function and the members here might be better able to help you.
GW
Edit : And, of course, as soon as I make the suggestion, someone comes along and proves me wrong. LOL
Kravvitz
03-03-2006, 02:02 AM
Change
document.ae.ab.text
to
document.forms[ae].elements[ab].value
OR (if you want the XHTML compatible way that doesn't work in IE4 and NS4)
document.getElementsByName(ae)[0].getElementsByName(ab)[0].value
Shane B
03-03-2006, 02:41 AM
well thanks for trying to help but that did not work either ... still the same error.
Line:41
Char:3
Code:0
Error:'document.forms[...].elements' is null or not an object
also here is how im calling it up ... maybe this is wrong but i doubt it ... cause like i said ... this code and everything else was working not to long ago and just decided to quit on me!
<input type='button' value='b' class='button' style='font-weight:bold;width:25px;' onClick=\"addText('sform', 'shortnews', '[ b][ /b]');\">
FYI: im coding all this in PHP and MySQL
Kravvitz
03-03-2006, 03:06 AM
Th server side language is irrelevant. The server-side language outputs X/HTML, CSS, and JavaScript.
Please view the source in your browser and post it here. From what you've shown so far the two solutions that I posted should have worked.
Quentin441
03-03-2006, 03:15 AM
if this
<input type='button' value='b' class='button' style='font-weight:bold;width:25px;' onClick=\"addText('sform', 'shortnews', '[ b][ /b]');\">
is how your html looks after the page loads then thats your problem... It should look like this
<input type='button' value='b' class='button' style='font-weight:bold;width:25px;' onClick='addText("sform", "shortnews", "[ b][ /b]");' />
Kravvitz
03-03-2006, 03:18 AM
Only if he's using XHTML. The terminator is illegal in HTML.
I expect he copied it from his PHP file before it had been parsed by the server, so the server hadn't removed the slashes.
Quentin441
03-03-2006, 03:20 AM
Just thought I would throw that out there because what you provided should be working.
Shane B
03-03-2006, 03:23 AM
yes i c&p it from my php script ... and nothing is wrong with it ... for some reason just this one javascript is not working on my server ... when i uped to another server and tested it ... it worked fine as a standalone and as a global script ... which is really weird :\
is it possible that my host has done something ?
Quentin441
03-03-2006, 03:27 AM
Then I have no clue without seeing the source.
Kravvitz
03-03-2006, 03:28 AM
Well thanks for trying to help. :)
I may be new to this forum, but I have literally thousands of posts on other web programming forums, so I know that people often post code that was written to be outputted by a server-side language. He also said he was using PHP, which does escape quotes like that when they are inside a quoted echo function call.
Quentin441
03-03-2006, 03:31 AM
I wasn't trying to put you down in any way. I was just tossing out ideas because what you provided him should be working and he said to look at the way he was calling it and I was just confirming that what he posted wasn't the resulting html of his php.
Shane B
03-03-2006, 03:36 AM
PHP Parsed:
<input type='button' value='b' class='button' style='font-weight:bold;width:25px;' onClick="addText('sform', 'shortnews', '[ b][ /b]');">
PHP Unparsed:
<input type='button' value='b' class='button' style='font-weight:bold;width:25px;' onClick=\"addText('sform', 'shortnews', '[ b][ /b]');\">
i know the code Kravvitz posted is correct cause it has worked before and does work when i test it on a different server ... but as i siad ... when place it on my main server ... it spits out the stupid ... is null or not an object error!
Kravvitz
03-03-2006, 04:04 AM
Shane, you could you post a link to the page?
I wasn't trying to put you down in any way. I was just tossing out ideas because what you provided him should be working and he said to look at the way he was calling it and I was just confirming that what he posted wasn't the resulting html of his php.
I didn't think you were. I thought you might have taken offense to my blunt response to your post. Oh well no harm done then.
Shane B
03-03-2006, 04:09 AM
yah no problem here it is ... not finished yet ... but the most of it is
Linkage (http://zickin.com/?module=register)
Kravvitz
03-03-2006, 04:19 AM
The problem is that you've got two forms named "sform" on that page.
You should use a complete doctype (one that includes a URL).
http://hsivonen.iki.fi/doctype/
http://www.alistapart.com/articles/doctype/
http://www.juicystudio.com/choosing-doctype/
http://www.w3.org/QA/2002/04/valid-dtd-list.html
Why tables for layout is stupid (http://www.hotdesign.com/seybold/index.html)
Why avoiding tables (for layout) is important (http://davespicks.com/essays/notables.html)
Why go table free? (http://www.workingwith.me.uk/tablefree/why/)
Nested Tables: About the (ab)use of tables as layout tools in webpages. (http://www.dorward.me.uk/www/nested/)
Tables Vs. CSS - A Fight to the Death (http://www.sitepoint.com/article/tables-vs-css/)
Why Tables Are Bad (For Layout) Compared to Semantic HTML + CSS (http://www.phrogz.net/CSS/WhyTablesAreBadForLayout.html)
The layout is dead, long live the layout (http://www.westciv.com/style_master/house/good_oil/dead_layout/)
Tables or CSS: Choosing a layout (http://evolt.org/article/Tables_or_CSS_Choosing_a_layout/25/21429/)
Shane B
03-03-2006, 04:24 AM
ummm i dont know what u saw ... but there is only one 'sform' on that page
<form name=\"sform\" action=\"?module=register&act=submit\" method=\"post\">
<table width=\"50%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#000000\" style=\"border: thin\">
<tr>
EDIT: ok sry about that ... i did not realize that on the shoutbox ... i had named that form 'sform' aswell ... i have fixed that problem along with the error!
its amazing how stupid little mistakes like that ... can mess u up for days if ur not paying attention ... much thanks for putting up with my simple mindedness :>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.