Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-13-2013, 06:23 AM   PM User | #1
Tamanna16
New to the CF scene

 
Join Date: Feb 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Tamanna16 is an unknown quantity at this point
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.

Tamanna16 is offline   Reply With Quote
Old 02-13-2013, 06:31 AM   PM User | #2
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
use the _ not the dot, i dont think . is a legal name character..


text_id
durangod is offline   Reply With Quote
Old 02-13-2013, 06:37 AM   PM User | #3
Tamanna16
New to the CF scene

 
Join Date: Feb 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Tamanna16 is an unknown quantity at this point
Thank you for your reply durangod. but can't change ID name. i have to go with text1.id.
any other suggestion???
Tamanna16 is offline   Reply With Quote
Old 02-13-2013, 07:22 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 02-13-2013, 07:34 AM   PM User | #5
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,447
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is offline   Reply With Quote
Old 02-13-2013, 08:41 AM   PM User | #6
Tamanna16
New to the CF scene

 
Join Date: Feb 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Tamanna16 is an unknown quantity at this point
thank you all for your valuable reply....
My work is done.
Tamanna16 is offline   Reply With Quote
Old 02-13-2013, 10:14 AM   PM User | #7
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,587
Thanks: 5
Thanked 864 Times in 841 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
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.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 02-13-2013, 09:08 PM   PM User | #8
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,447
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is offline   Reply With Quote
Reply

Bookmarks

Tags
html, javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:46 PM.


Advertisement
Log in to turn off these ads.