02
Dec
07

Autogenerate Id in Javascript

This is a little funtion for creating autogenerated Ids

//Declare some variables
var rand
var anotherNumber
var str
var myDate
var strDate
var text
rand= Math.random();
anotherNumber = rand + '';
str = anotherNumber.substr(2,4);
myDate = new Date();
strDate = myDate.getMonth() + '' + myDate.getDate() + '' + myDate.getYear();
text = 'yourResumedEntity'+ strDate + str;

Kind of simple, but worked


1 Response to “Autogenerate Id in Javascript”


  1. 1 Bhaskar Rabha
    October 14, 2009 at 10:04 am

    function uniqid(str)
    {
    var id = 0;
    var flag=true;

    while(flag)
    {
    if(document.getElementById(str + id) == null)
    {
    return str + id;
    flag=0;
    }else
    id++;
    }

    }

    var id=uniqid(’str’);

    i have another solution for elements.


Leave a Reply




 

December 2007
M T W T F S S
« Nov   Jan »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Flickr Photos

Eid mubarak :)

Night - Red White and Blue!

Storm over the Thames

UT 3, 4 & The Milky Way [video]

An ocean between us.

IV

morning view

A shot in the light

Untitled

54. This is the view from the other side.

More Photos

Leave your comment

Blog Stats

  • 119,326 hits