Results 1 to 9 of 9

Thread: Accessing a form element with a space in between [Resolved]

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Resolved 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?
    Last edited by mendhak; Jan 18th, 2005 at 03:59 AM.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Accessing a form element with a space in between

    - Why does it have a space?

    You could try:

    document.formname["element name"]
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width