Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking number of chars

Status
Not open for further replies.

Deam

Programmer
Oct 10, 2000
68
US
I need to specify in a function that if the value entered by the user is less then 6 digits then add 0's in front.
The function gets called when the user hits a button from the front-end.
This is the code I have so far...
function NextJobID()
{
var sSQL = "EXECUTE sp_JobValue 'JobID'";
rdcCOUNTER.executeSQL(sSQL);
var rsWork = rdcCOUNTER.getRecordset();
var nextID = rsWork.fields("COUNTER").Value;
txtJobID.value = '00' + nextID;
wiz.setData("JobID", txtJobID.value);
}

Any help will be greatly appreciated.

Thanks !!
 
i think this is server side jscript, i think the below function should work for you

function NextJobID()
{
var sSQL = "EXECUTE sp_JobValue 'JobID'";
rdcCOUNTER.executeSQL(sSQL);
var rsWork = rdcCOUNTER.getRecordset();
var nextID = rsWork.fields("COUNTER").Value;
// txtJobID.value = '00' + nextID;
var nextlength = nextID.length;
var zerostring = "";
if (6-nextlength>0) {for (i=1;i<6-nextlength;i++) {zerostring +=&quot;0&quot;} }
txtJobID.value = zerostring +nextID;

wiz.setData(&quot;JobID&quot;, txtJobID.value);
}
 
sjravee,
This code works great as long as the user enter less than 6 chars. If the user enters 6 or more then it should accept whatever the user has entered. Aslo is there a way to check if the value has already been used ? if yes then it should pop up a message.

Thanks in advance :)
 
it should allow for for than six as the if statement will only start the for loop if 6 - nextID length is greater than 0, if the nextID was anymore than six then no zeros would be added.

You would have to build a global array and check it for nextID before adding the it the value to the array. its relatively easy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top