Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Can not pass ID with dot(.) and (-) to javacript

    Html code:
    <input id="text.id" type="text" onFocus="dosomething(this,'text1.id')">
    <input id="text1.id" type="text">

    i am trying to do something like above, i'm trying to pass id(text1.id) with function dosomething() but its not working.
    please help me.


  • #2
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,368
    Thanks
    262
    Thanked 32 Times in 31 Posts
    use the _ not the dot, i dont think . is a legal name character..


    text_id

  • #3
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for your reply durangod. but can't change ID name. i have to go with text1.id.
    any other suggestion???

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    Quote Originally Posted by Tamanna16 View Post
    Thank you for your reply durangod. but can't change ID name. i have to go with text1.id.
    any other suggestion???
    Well, in that case you are in the craperoo as the Australians would say. A period (dot) is not a legal character in an element id (or a name).

    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.

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,592
    Thanks
    0
    Thanked 644 Times in 634 Posts
    That id wouldn't work for anything else either - not just JavaScript.

    In CSS #text.id would be looking for an element with id="text" and class="id" and wouldn't match the id you have.

    I can't think of why someone would want to target an input field but I doubt that <a href="text.id"> would link to that field properly either.

    That's all three possible uses for an id with at least two and probably all three of them not working when the id contains an illegal dot.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you all for your valuable reply....
    My work is done.

  • #7
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,607
    Thanks
    6
    Thanked 997 Times in 970 Posts
    Quote Originally Posted by felgall View Post
    I can't think of why someone would want to target an input field but I doubt that <a href="text.id"> would link to that field properly either.
    The ID on inputs is used for labels. I don’t know whether the link is made if there is a period in the ID, though.

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,592
    Thanks
    0
    Thanked 644 Times in 634 Posts
    Quote Originally Posted by VIPStephan View Post
    The ID on inputs is used for labels. I don’t know whether the link is made if there is a period in the ID, though.
    It appears that the id does still work for linking a label to an input even when the id contains garbage - at least in all the popular browsers. That is the one instance where a period doesn't apply a different meaning in one place to what it does at the other. You wouldn't be able to access the forHTML value from JavaSript though because it too would misinterpret the dot.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Tags for this Thread

    Posting Permissions

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