Hey there!
Im using registry format guids in my database as primary keys. My website uses these values to assign id's to html objects. However when i wana use javascript to interact with the html objects it will not work. If i use a number id like "123" my functions run
fine but using a guid, example
c119c647-c825-4f1b-8eb6-7220cbb88a93
they wont. Is there a way to generate some kind of unique ID in .net that will work when used with javascript??
Thanks
Tom[H]
-
-
tomtech999 wrote:Hey there!
Im using registry format guids in my database as primary keys. My website uses these values to assign id's to html objects. However when i wana use javascript to interact with the html objects it will not work. If i use a number id like "123" my functions run fine but using a guid, example
c119c647-c825-4f1b-8eb6-7220cbb88a93
they wont. Is there a way to generate some kind of unique ID in .net that will work when used with javascript??
There's no reason why guids for HTML ids shouldn't work ... what errors do you get?
(And this was probably better posted in TechOff)
-
Are you using quotes around the value?
-
Oh! thanks for that i added quotes and it worked!
WHy should that guid need quotes and not 123??? -
Ok every occasion i use this in javascript i get
missing ) after argument list
example use
function
function highlightRowD(itemid)
{
var row=document.getElementById(itemid);
row.style.backgroundColor="#404040";
row.style.color="white";
var links=row.getElementsByTagName("a");
for(var i=0;i<links.length;i++)
{
links[i].style.color="white";
}
var descriptionelement=itemid+'desc';
var description=document.getElementById(descriptionelement).style.display="block";
}
object
<tr onMouseOver='highlightRowD(c119c647-c825-4f1b-8eb6-7220cbb88a93)'>
<td>some cell</td>
</tr>
As i mentioned before, i try this with the id of the row as "123" and
it works fine
-
Because 123 is a valid numeric constant, and c119c647-c825-4f1b-8eb6-7220cbb88a93 isn't. If you put quotes around it, JavaScript will treat it as a string.
-
Speaking of GUID, what do you all use to generate GUIDs?
-
zhuo wrote:Speaking of GUID, what do you all use to generate GUIDs?
This might be a stupid question, but why exactly does one need GUIDs and why are they so special that people sell and buy them on ebay?
Couldn't just incrementing an int in a db be fine for a primary key? -
mVPstar wrote:
This might be a stupid question, but why exactly does one need GUIDs and why are they so special that people sell and buy them on ebay?
Couldn't just incrementing an int in a db be fine for a primary key?
Well it depends what you are using it for.
If, for example, you wanted a unique ID that wasn't easily guessed, then an incrementing integer is not suitable. Or an ID suitable for replication control.
-
mVPstar wrote:

zhuo wrote: Speaking of GUID, what do you all use to generate GUIDs?
This might be a stupid question, but why exactly does one need GUIDs and why are they so special that people sell and buy them on ebay?
Couldn't just incrementing an int in a db be fine for a primary key?
GUIDs, as the name implies, are (very likely to be) globally unique. In a DB table, most of the time you only need to be unique within that one table so an autoincremented value will do just fine. If you need to have a key value that's unique beyond the confines of the table you need a GUID (Blowdart's given some good reasons too).
GUIDs main usage is in COM. If I build a COM component, it needs to have a unique identifier that will be unique no matter what computer my component is used on. GUIDs do that nicely.
The best way to generate GUIDs on Windows is by using the CoCreateGuid API function or using a tool that uses that function, such as guidgen.exe which comes with the Platform SDK and Visual Studio.
People who sell GUIDs on eBay are just stupid (though not as stupid as people who would buy them
)
-
mVPstar wrote:

zhuo wrote: Speaking of GUID, what do you all use to generate GUIDs?
This might be a stupid question, but why exactly does one need GUIDs and why are they so special that people sell and buy them on ebay?
Couldn't just incrementing an int in a db be fine for a primary key?
GUID have many different applications, apart from the ones already mentioned.
A practical situation where you would need a GUID in a database driven application is when you are build an application with future proofing in mind.
E.g. if you build an application to run within a single office to start with and business seems to be going well and you've decided to open up a few other offices around the country. As the business grow, you've found the need to do reporting across the enterprise or wishes to serve information from a single source for various reasons, so you've decided that you need to consolidate all these information and , having a GUID as unique identifier rather than autoincrement columns allow you to easily consolidate all these information without hell break loose. Well, it will allow you to do it with minimal fuss without worrying about PK conflicts etc.
James Zhuo
Application Development Consultant
-
Ah, thanks guys.
-
Thanks for the help guys, glad i created a nice discussion!

In this example i am using guids to keep items on my site completely separate as these items will be used in other places other than the database, for example stored in files, or sent as print jobs. Using GUIDS just means that whatever extra modules I add to my app I will never get conflicting primary keys or file names etc
Thanks again
Tom -
zhuo wrote:Speaking of GUID, what do you all use to generate GUIDs?
in boxely...
var guid = appUtils.generateGUID();
if (guid)
{
shell.print(guid);
}
-
Note the XHTML 1.0 spec recommends only using id values that match the regex:
[A-Za-z][A-Za-z0-9:_.-]*
In particular, any id= attribute that begins with a number (5/8 of all GUIDs) is iffy. -
There's a SqlDbType in .NET 2.0 and SQL 2005(I think that's the combo) SqlDbType.UniqueIdentifier. It lets you do GUIDs instead of an int for primary keys and stuff.
-
Matthew van Eerde wrote:
Note the XHTML 1.0 spec recommends only using id values that match the regex:
[A-Za-z][A-Za-z0-9:_.-]*
In particular, any id= attribute that begins with a number (5/8 of all GUIDs) is iffy.
A specification that "recommends". I don't like the sound of that
-
Harlequin wrote:A specification that "recommends". I don't like the sound of that

Well, it recommends for backcompat.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.