9 Replies - 5327 Views - Last Post: 12 October 2012 - 07:23 AM

#1 Vomster  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 198
  • Joined: 15-May 08

Using a colon in an ID name

Posted 24 January 2009 - 09:40 AM

How can I get this to work? "this" being the name of the id using colons in there.

<input type="text" id="section:login:username" name="username">



I've tried these two but neither work. The second I found through searching.

#section:login:username {}

#section\:login\:username {}


This post has been edited by Vomster: 24 January 2009 - 09:41 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Using a colon in an ID name

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1153
  • View blog
  • Posts: 7,166
  • Joined: 07-September 06

Re: Using a colon in an ID name

Posted 24 January 2009 - 09:59 AM

After a quick search it doesn't look like it is possible. If you change it to this it works, but that isn't using colons...

<style>
#section_login_username{
  border: 1px solid #f00;
}
</style>

<input type="text" id="section_login_username" name="username">

Was This Post Helpful? 0
  • +
  • -

#3 Vomster  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 198
  • Joined: 15-May 08

Re: Using a colon in an ID name

Posted 24 January 2009 - 10:37 AM

I thought about doing that way but figured I'd pursue this. I viewed some source code for a site that had their IDs with the colons so it definitely has me curious as to whether or not it's possible.
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5345
  • View blog
  • Posts: 27,296
  • Joined: 10-May 07

Re: Using a colon in an ID name

Posted 24 January 2009 - 11:20 AM

Why do you need to use the colon? It's a special character. Even if you could get away with using it, it may not work with all browsers.
Was This Post Helpful? 0
  • +
  • -

#5 Vomster  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 198
  • Joined: 15-May 08

Re: Using a colon in an ID name

Posted 24 January 2009 - 11:23 AM

I don't 'need' to I just wanted too. And I was just curious as to how they got it to work.

I think I'm going to use _ instead.
Was This Post Helpful? 0
  • +
  • -

#6 Arenlor  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 34
  • View blog
  • Posts: 389
  • Joined: 26-April 06

Re: Using a colon in an ID name

Posted 24 January 2009 - 12:48 PM

I don't think they did.
Was This Post Helpful? 0
  • +
  • -

#7 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: Using a colon in an ID name

Posted 26 January 2009 - 02:32 AM

That example looks like it's for the benefit of some javascript. Colons in CSS are used to declare states of an element, so a:hover indicates a link that the user has their mouse over.
Was This Post Helpful? 0
  • +
  • -

#8 Vomster  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 198
  • Joined: 15-May 08

Re: Using a colon in an ID name

Posted 26 January 2009 - 06:28 AM

This is straight from their page:

<p>
<label for="content:registrationForm:username">Choose a user name</label>
<input id="content:registrationForm:username" name="content:registrationForm:username" type="text" value="" class="inputText" />
</p>


Although, now that I look at the input tag more closely, I see they are using the class tag as well. Is it possible to use the id name like that with javascript?

I know that is a javascript question and we are in the html/css so don't flame me. I don't want to start another thread for this somewhere else as this will die soon.
Was This Post Helpful? 0
  • +
  • -

#9 kaheidt  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 12-October 12

Re: Using a colon in an ID name

Posted 12 October 2012 - 07:15 AM

I realize this was posted almost two years ago at this point, but I figured what the heck, might as well put in a follow up in case other people are searching the internet like I am.

I came across this issue as well and thought "why is it doing this?", especially since I had colons in IDs of other items on my page. Then I realized that those other items that DO have it are ones where I've set the ID programatically. It has to do with the way that Visual Studio creates it's designer files when you add a component to the aspx markup. It doesn't like the colon in the ID because the colon causes the ID to be separated in the designer code, since colons are special characters that are used for other purposes in your vb or c# code. If you really want to have colons in it, you can use the underscores in the ID for the control, then in the Load event you can replace the underscores in the .ID property to be colons.

For me, I'm already using an underscore in the ID for a different purpose. So, since the underscore is the only special character allowed in an ID, I decided to use two underscores next to each other as a placeholder for a colon.

<asp:HyperLink runat="server" ID="createBtn_IssueID__NEWISSUE" CssClass="link-button createBtn" 
NavigateUrl="#dialog-issue-response">Create a New Issue</asp:HyperLink>


Then in my Page_Load, I have the following code:

createBtn_IssueID__NEWISSUE.ID = Replace(createBtn_IssueID__NEWISSUE.ID, "__", ":")


This results in createBtn_IssueID__NEWISSUE.ID now being set to createBtn_IssueID:NEWISSUE. But you can still do other programming with this control in your code by continuing to use createBtn_IssueID__NEWISSUE in your code, because that's really a control reference variable that's pointed to the control at runtime. Don't think that since you've changed the ID of the control to now have a colon in it that the control reference variable with the two underscores now points to a control that no longer exists.
Was This Post Helpful? 1
  • +
  • -

#10 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5345
  • View blog
  • Posts: 27,296
  • Joined: 10-May 07

Re: Using a colon in an ID name

Posted 12 October 2012 - 07:23 AM

Thank you for the detailed description!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1