[Javascript] any way to add a zero to a number

Peter Brunone peter at brunone.com
Thu Jun 13 12:25:41 CDT 2002


Scott,

	It looks like you're doing exactly what you need to do already in the
server-side VBScript.  However, you're trying to use a string as the
client-side array index, and I don't think you can do that.
	Either make two arrays (one for office name and one for office number), or
just pull the number parameter in and ParseInt() it so it matches the array
when you want to select it.  Will this work, or is there more to the
solution?

Regards,

Peter

|-----Original Message-----
|From: javascript-admin at LaTech.edu [mailto:javascript-admin at LaTech.edu]On
|
|where would I put this?
|
|<the code>
|
|<%
|
|'---------------------------------------------------------------
|'---------------------------------------------------------------
|'---------------------GET offices FROM DATBASE------------------
|'---------------------------------------------------------------
|'---------------------------------------------------------------
|	dim  OfficeNameNumber(2000),countarray
|
|   	set cmd = nothing
|	set cmd = server.CreateObject("ADODB.COMMAND")
|	with cmd
|		.ActiveConnection		= cnn
|		.CommandText 			= "get_active_offices"
|		.CommandType 			=  adCmdStoredProc
|	end with
|	set rst = cmd.execute
|
|	DO WHILE not rst.eof
|		if rst("franchiseid") then
|
|		   OfficeNameNumber(rst("franchiseid")) = rst("officename")
|
|	   end if
|     	rst.movenext
|   LOOP
|
|'  ReDim Preserve OfficeNameNumber(countarray)
|	rst.close
|	set rst = nothing
|   	set cmd = nothing
|
|
|'response.write "<p>"& OfficeNameNumber(789)
|
|
|%>
|
|
|<SCRIPT LANGUAGE="JavaScript">
|<!-- Begin
|
|     officearray = new Array(2000);
|
|  <% for x = lbound(OfficeNameNumber) to ubound(OfficeNameNumber) %>
|     <% if OfficeNameNumber(x) <> "" then %>
|          officearray[<%=right("0000"+x,4)%>]= '<%=
|replace(OfficeNameNumber(x),"'","\'") %>';
|     <% end if %>
|
|  <%next%>
|
|
|function getofficename(number,thefield)
|{
|   if(officearray[number]>"")
|   {
|     thefield.value = officearray[number];
|   }
|}
|//-->
|</script>
|
|-----Original Message-----
|From: Muchacho, Laurent (TWIi London) [mailto:LMuchacho at twii.net]
|
|Hi scott
|
|I think Josiah Gordon already answer to that question
|
|Laurent
|
|-----Original Message-----
|From: Josiah Gordon [mailto:jgordon at directfile.com]
|
|Try creating a string variable and appending your variable to
|"000". In your
|database read the var in as an int.
|
|	var str = "000";
|	var num = 1;
|	str += num;
|	document.write(str); // ==> 0001
|
|That work?
|
|Josiah Gordon
|
|
|-----Original Message-----
|From: javascript-admin at LaTech.edu [mailto:javascript-admin at LaTech.edu]On
|
|I really want 0001
|but I get 1..
|
|this is not good
|for my database
|
|Scott
|
|p.s. Thanks for everyone's help so far.




More information about the Javascript mailing list