Web Analytics Made Easy -
StatCounter Accessing a variable with character dot(.) inbetween its name - CodingForum

Announcement

Collapse
No announcement yet.

Accessing a variable with character dot(.) inbetween its name

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Accessing a variable with character dot(.) inbetween its name

    In my html form, I have an input box with name “contact.area”.

    <form name = “contactinf”>
    <Input type =”text” name = “contact.area” value =”100”>
    </form>

    Now I can’t access the text box value through java script, since the “.” Character makes the script to think ‘contact’ alone as an object.

    function myfunction()
    {
    alert(document.contactinf.contact.area.value);
    }

    As per the requirements, I cannot change the name of the text box.
    Is there any chance for me to fetch the value

  • #2
    You should rename your input box contactArea, or contact_area. The effect of the period (dot) is as you have discovered.

    "As per the requirements, I cannot change the name of the text box." Why not?

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

    Comment


    • #3
      Try accessing it as document.forms['form.name'].elements['element.name']
      liorean <[[email protected]]>
      Articles: RegEx evolt wsabstract , Named Arguments
      Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
      Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

      Comment

      Working...
      X