SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Oct 2001
    Location
    tampa florida
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    whitespace trouble in form element names w/javascript

    hello,

    i am having difficulty using javascript to validate form fields with whitespaces in the element names (ex: First Name, Last Name).

    here's a code snippet:
    ###
    function validate(formObj) {

    if (document.form1.Payment Method.checked){
    do something here...}
    ###

    the problem is that javascript won't read the element "Payment Method" unless i mash the name into one word. (i don't want to do that because i later use the element names to provide a printable customer receipt

    i tried using the ascii octal number for a whitespace in the above code (...form1.Payment\040Method.checked...), but to no avail.

    any advice would be greatly appreciated.

    thanks,
    mupledge
    mupledge@hsc.usf.edu

  2. #2
    SitePoint Zealot Atirez's Avatar
    Join Date
    Nov 2000
    Location
    England
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    try accessing the form elements using the array [] operators; like this:

    Code:
    document.forms["form1"].elements["payment method"].checked
    Hope this helps
    Atirez

  3. #3
    SitePoint Member
    Join Date
    Oct 2001
    Location
    tampa florida
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    atirez,

    works like a charm.
    many thanks.


    -mupledge


Bookmarks

Posting Permissions

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