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

Scott.Wiseman swiseman at remax-cahi.com
Thu Jun 13 12:28:42 CDT 2002


I see the javascript function
being passed the 0788 and the 0789
but it does not get the office

when I pass it the 0001
it does get the office..

what gives

officearray[0788]='office in the valley';
officearray[0789]='office in the hills';

-----Original Message-----
From: Scott.Wiseman 
Sent: Thursday, June 13, 2002 10:20 AM
To: 'javascript at LaTech.edu'
Subject: RE: [Javascript] any way to add a zero to a number


officearray[0001]='office test';
officearray[0004]='office test';
officearray[0006]='office test';
officearray[0008]='office test';

OK I got it to work with this code:

  <% for x = lbound(OfficeNameNumber) to ubound(OfficeNameNumber) %>
     <% if OfficeNameNumber(x) <> "" then %>
   <%response.write
"officearray["&right("0000"&x,4)&"]='"&replace(OfficeNameNumber(x),"'","\'")
&"';" &vbcrlf%>
     <% end if %>
  <%next%>

but when I pass it "0001" it does not find the "0001"
but when I pass it the "1" it finds the "0001"

what is going on here...

-----Original Message-----
From: Peter Brunone [mailto:peter at brunone.com]
Sent: Thursday, June 13, 2002 10:26 AM
To: javascript at LaTech.edu
Subject: RE: [Javascript] any way to add a zero to a number


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.

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript



More information about the Javascript mailing list