By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,730 Members | 1,620 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,730 IT Pros & Developers. It's quick & easy.

Easy Javascript question (getting dropdown list values)

yarbrough40
100+
P: 320
I'm a vb.net user mostly... can anyone tell me why I'm getting a runtime error 'permission denied' when running this? trying to get values from a dropdownlist.

Expand|Select|Wrap|Line Numbers
  1.  
  2. function getvalues()
  3. {
  4. var dl = document.getElementById("DropDownList11");
  5. var item1;
  6.  
  7. item1 = dl.options[0].value;
  8. document.write(item1 + "<br>");
  9.  
  10. item1 = dl.options[1].value;      //error occurrs here
  11. document.write(item1 + "<br>");
  12. }
  13.  
Dec 15 '09 #1
Share this Question
Share on Google+
8 Replies


Dormilich
Expert Mod 5K+
P: 8,639
I think that happens when you try to use document.write() on an already loaded document. document.write() is not suited to modify a HTML page.
Dec 15 '09 #2

yarbrough40
100+
P: 320
thanks Dormilich, however that's not the answer. I can tell because this simple code executes without error...
Expand|Select|Wrap|Line Numbers
  1. function getvalues()
  2. {
  3. var string = "hello" + "<br>";
  4. document.write(string); 
  5.  
  6. string = "world";
  7. document.write(string); 
  8.  
in my first example I show exactly where the error occurs and it's at the second time I use 'document.getElementById'... is there perhaps some kind of fundamental Java violation when attempting to get values from an object more than once?
Dec 15 '09 #3

Dormilich
Expert Mod 5K+
P: 8,639
in my first example I show exactly where the error occurs and it's at the second time I use 'document.getElementById'...
sometimes the line that throws an error is not the line that causes it

anyway, I cant see you using getElementById() twice.

if you can provide a link, Ill have my FireBug peek at it.
Dec 15 '09 #4

yarbrough40
100+
P: 320
I figured it out and you are mostly correct! you can use document.write as often as you like. the problem is that I can pull the first value from the dropdown control but once I document.write that value to the new page, I am unable to reference that same control because it no longer exists. in this case I must compile all of my values first then write to the page...

thanks for pointing me in the right direction. problem solved!
Dec 15 '09 #5

Dormilich
Expert Mod 5K+
P: 8,639
in this case I must compile all of my values first then write to the page...
or use a more appropriate method like DOM.
Dec 15 '09 #6

gits
Expert Mod 5K+
P: 5,390
or use a more appropriate method like DOM
that way is definitly to prefer, document.write() shouldn't be used or when it has to ... then at least with the corresponding open() and close() methods.

kind regards
Dec 15 '09 #7

yarbrough40
100+
P: 320
thanks - I really have no reason to use document.write. this was only used as a test to see if I could get at the values. it is a common practice in .net using response.write. the difference is that response.write does not instantiate a new page so the data objects you reference will persist and no errors will occur. It's a simple matter of understanding my environment : )
Dec 15 '09 #8

acoder
Expert Mod 15k+
P: 16,027
is there perhaps some kind of fundamental Java violation...
Sorry to be picky, but it's important. Java and JavaScript are two very different languages. It's important to make the distinction.
Dec 21 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.