[Javascript] any way to add a zero to a number
Scott.Wiseman
swiseman at remax-cahi.com
Thu Jun 13 13:17:10 CDT 2002
function getofficename(number,thefield)
{
var num1,num;
num1 = number.toString();
alert(num1); ---------------this will give me the "0789"
num = parseInt(num);
alert(num); ------------------this will give me the 7
if(officearray[num]>"")
{
// alert(number);
thefield.value = officearray[num];
}
}
-----Original Message-----
From: Scott.Wiseman
Sent: Thursday, June 13, 2002 10:42 AM
To: 'javascript at LaTech.edu'
Subject: RE: [Javascript] any way to add a zero to a number
can index be non-integers?
I am reading in the book
that I can have an array like this
somearray['scott']='programmer'
is this possible
and if so why isn't this working
-----Original Message-----
From: Peter Brunone [mailto:peter at brunone.com]
Sent: Thursday, June 13, 2002 10:46 AM
To: javascript at LaTech.edu
Subject: RE: [Javascript] any way to add a zero to a number
That's exactly what should happen. You pass it the index, and it
finds the
corresponding value in the array.
|-----Original Message-----
|From: javascript-admin at LaTech.edu [mailto:javascript-admin at LaTech.edu]On
|Behalf Of Scott.Wiseman
|
|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]
|
|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
|
_______________________________________________
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