Archer
Archer

Reputation: 81

What does this mean in javascript?? var leave =<%=seconds %>;

I got this code from net but i'm not able to interpret its meaning..

var leave =<%=seconds %>;  

Kindly help me...

Upvotes: 0

Views: 140

Answers (4)

Michael Slade
Michael Slade

Reputation: 13877

It's javascript with a snippet of JSP/ASP/ERB code.

the part in between <%= and %> is evaluated on the server when the request is made, and the result is inserted into the HTML.

So if, say, the value of seconds on the server is 42, then

var leave =<%=seconds %>;

gets turned into

var leave =42;

and that's what the browser gets.

Upvotes: 0

Priyank Patel
Priyank Patel

Reputation: 6996

It is to refer or access serverside control on client side.

<asp:Textbox id="myTextbox"  runat="server"/>
var val=<%=myTextbox.ClientID%>

Upvotes: 0

n00dle
n00dle

Reputation: 6043

It looks like a mixture of JS and (e.g) ASP:

  • var leave create a new variable called leave
  • <%=...%> is the shorthand for outputting a value in ASP
  • seconds is an ASP variable

Upvotes: 1

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181290

That's not JavaScript. That's Java script generated by a server side template/scripting language such as JSP or ASP.NET.

So, when your server process the output that will be send to the browser your JavaScript will actually look like:

var leave = 40;

Where 40 is the value of seconds variable in the server side scripting language you are working on.

Upvotes: 5

Related Questions