Accessing a form element with a space in between [Resolved]
If I have a dropdown box named so:
Code:
<select name="Dev. Domain">
How would I access it using Javascript?
I tried
document.getElementById("Dev. Domain")
but apparently Firefox doesn't seem to like it. And I am not quite sure it can be used in
document.formname.Dev. Domain (?)...
Any tips?
Re: Accessing a form element with a space in between
You will need to give it an id if you use the getElementById method.
If you want to access it via the form you would use the form name: document.formname.elementname which will provide you with an array of option elements.
Re: Accessing a form element with a space in between
Quote:
Originally Posted by visualAd
You will need to give it an id if you use the getElementById method.
If you want to access it via the form you would use the form name: document.formname.elementname which will provide you with an array of option elements.
And what if it's called "element name"?
document.formname.element name
does not look right.
Re: Accessing a form element with a space in between
:eek: - Why does it have a space?
You could try:
document.formname["element name"]
Re: Accessing a form element with a space in between
I can't do anything about the space. Working with an existing form here. :(
Thanks for the reply. You're useful for something. :)
Re: Accessing a form element with a space in between
Quote:
Originally Posted by mendhak
I can't do anything about the space. Working with an existing form here. :(
Thanks for the reply. You're useful for something. :)
But was I. I would be interested to know if my suggestion worked, because I cannot be bothered to find out myself.
Re: Accessing a form element with a space in between [Resolved]
I went with the getElementById(" ") thing. I had forgotten to put an id attribute in there, as you pointed out.
I don't have the page with me right now. Wanted to get rid of it as soon as possible.
Re: Accessing a form element with a space in between [Resolved]
A space is not valid in either the id or name attribute. Browsers will accept it, of course (I think they're far too forgiving), but it's not valid according to the HTML specs and can therefore cause all kinds of problems.
Re: Accessing a form element with a space in between [Resolved]
As it should be. I was working on an existing HTML page that linked to an existing web application that had that parameter. I don't know what was going through their minds at the time, but it's what they put in. I'm glad I get someone to blame in this case :p