|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need help on this javascript
I have this code.
<SCRIPT language=JavaScript> function IVA() { //alert("Entro en IVA"); a = <%=${fila.preciototal_Protocolo}%>; IVA = a*0.17 alert(IVA); return IVA; } </SCRIPT> where ${fila.preciototal_Protocolo} its a value I get from my server doing <c:forEach var="fila" items="${requestScope.factura_persona}"> (this is JSTL) Please help me out. Thanks! |
|
#2
|
||||
|
||||
|
Is this a Javascript question, or JSTL?
What is this code supposed to do? What does the rendered html end up looking like? |
|
#3
|
|||
|
|||
|
Quote:
It is a javascript question. What its supposed to do is to calculate a tax. The idea its to get the value from ${fila.preciototal_Protocolo} and multiply it by 0,7 and return that value so I can print it in my page. Its a bill. Thanks! |
|
#4
|
||||
|
||||
|
So what happens when you run the page?
What does the rendered source code look? A common problem is the server variable isn't passed to the Javascript properly. |
|
#5
|
|||
|
|||
|
Quote:
I dont know what you mean here sorry. But the page Its not loading I know its the part when I get the server variable because if I comment it it shows me the alert... But I print the server variable outside the script and loads with no problems |
|
#6
|
||||
|
||||
|
That's cos you can't print server variables into JS like that.
You have to Response.Write() [you are using ASP, right?] it all: Code:
<%
Response.Write("<script tyoe='text/JavaScript'>");
Response.Write("function IVA() {");
Response.Write("//alert('Entro en IVA');");
Response.Write("a = '"& ${fila.preciototal_Protocolo} &"';");
Response.Write("IVA = a*0.17");
Response.Write("alert(IVA);");
Response.Write("return IVA;");
Response.Write("}");
Response.Write("<\/script>");
%>
HTH. <edit>Oh, wait, you aren't using ASP, you'r using jstl. Er, I dunno anything about jstl, but the idea is still the same. Just replace the 'Response.Write();' bits with whatever jstl uses to output stuff. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Need help on this javascript |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|