Question:
javascript getElementById issues?
Vegard Blix
2013-01-21 01:40:02 UTC
If I try to inject some scripts in the adress bar, for instance "document.getElementById('paragraph').innerHTML='test';" - everything on the webpage disappears and instead displays 'test' (without the quotes). The same thing happens when I try javascript:document.getElementById('divName').style.width="500px"; - the webpage disappears and now only displays '500px' without the quotes. document.getElementById('divName').style.width does return "200px" when I try to alert it though.

Is it supposed to work like this? This is what my div looks like:

Three answers:
Kookiemon
2013-01-21 02:22:57 UTC
The use of the Javascript protocol is generally discouraged. It's much easier to use the ONCLICK event attribute to either contain the script or call a Javascript function and then "return false;" to cancel the click.



eg.

< A HREF="#" ONCLICK="modifyDIV( "divName", 200, 200); return false;"> Modify DIV< /A>



The use of HREF = "#" allows the link to fail gracefully should the visitor have Javascript disabled. The "return false;" cancels the click. If the click does succeed, the "#" would reload the page and go back to the top of the page. Reloading the page is bad for your script, hence the "return false", as it would stop it from running any further.



To elaborate on the Javascript protocol. It is unable to receive any output so you should never use any functions or operations that return a value. Without seeing the entirety of the script you used, it's impossible to say what you were doing incorrectly.
Jim
2013-01-21 01:59:51 UTC
getElementById should work with no troubles for stuff that is in the document and has an id.



yahoo obliterated your code, you need to use spaces on yahoo answers.



so I don't know what exactly your question is. repost with better content & try to be nice to to web visitors of your site.



don't do that. try something different. it's not going to work well. I hope you are doing good.
?
2016-10-18 08:59:30 UTC
Wowowowowo, carry on... merchandise oriented Programing would make this alot ton much less complicated on you. particularly of being very redundant on your code via calling out each and every textbox, basically placed some thing like... for (i=0, j=rfile.getElementsByTagName("enter")... i


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...