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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript variable in asp 1

Status
Not open for further replies.

Papa Bear

Programmer
Feb 1, 2003
37
GB
Hi All

I have the following script in an ASP page which is activated by a button onclick.
Code:
function Updatedate(var1,var2) {
    var D1 = Date.parseExact(document.getElementById("DateID"+var1).value,"d/M/yyyy");
    var n = <%=sysRS("gap"+var1)%>;
    var D2 = D1.addWeeks(n);
    var D3 = D2.toString("dd/MM/yyyy")
    document.getElementById("DateID"+var2).value = D3;
}
I just can not get the right format for the line starting "var n ="

If I change it to
Code:
    var n = <%=sysRS("gap1")%>;
it works, but I want to be able to change the 1 to the value held in var1 which will be 1 to 4.

Any ideas please
 
The problem that you have here is

1) The <% .. %> part is done first at the server end

2) var1 is only known at runtime so it cannot be passed to the server

One way around it would be to use a switch statement. Something like
Code:
var n;
switch (var1)
{
case 1:
   n = <% sysRS("gap1") %>;
   break; 
case 2:
   n = <% sysRS("gap2") %>;
   break; 
   ...
}
It is tedious but it will work.
 
Thanks for that. Worked a treat. Do I need to close this thread? If so, how.
 
No need to close the thread. I think it gets automatically closed after a few months. Thanks for the star.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top