Florin M.
Florin M.

Reputation: 2169

syntax error in javascript inside asp page

    <script type="text/javascript">
            /* <![CDATA[ */
            var on_id = 1;

     if (<%=GetValue() %>) {
                on_id  = <%=GetValue() %>; 
            }
   </script>

I do get 2 syntax errors: at the 2nd closed brachet: after %> and at ; after again %>. GetValue() is a public decimal method defined in code behind.

How can I achieve this?

Upvotes: 1

Views: 172

Answers (3)

Hadi Mohammadi
Hadi Mohammadi

Reputation: 434

Try this

   <script type="text/javascript">
        var on_id = 1;
        <%if (GetValue()) {%>
            on_id  = '<%=GetValue() %>'; 
        <%}%>
   </script>

Upvotes: 0

Sujit.Warrier
Sujit.Warrier

Reputation: 2869

im not an expert but i had faced a similar problem.it got solved by putting <%=GetValue() %> in ''(single quotes) i.e '<%=GetValue() %>' so i stopped getting syntax errors

use parseFloat() function to get the float value from the string

Upvotes: 1

AkshayJ
AkshayJ

Reputation: 769

 $.ajax({
      type: "POST",
      url: 'yoururl/GetValue',
      data: "{}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
     success: successFunction,
    error: errorFunction
    });

Do it using an AJAX call :)Check the condition in successhandler

Upvotes: 0

Related Questions