Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
117
rated 0 times [  123] [ 6]  / answers: 1 / hits: 18800  / 11 Years ago, tue, april 30, 2013, 12:00:00

Let say I have the following javascript



function blob(alertText) {
alert(alertText);
}


I would like to call the function within my view. something like:



<% if (x == 0)
//Need to Call the javascript function here. e.g. blob(sometext);
%>


How can I call the the javascript function within the enclosed if statement in my view?


More From » jquery

 Answers
32

Try:



<% if (x == 0) { %>
<script type=text/javascript>blob(sometext);</script>
<% } %>


Since the Javascript needs to be put on the page, you need to close off the <% %> tags so that you can print HTML. The specific HTML needs to be a <script> tag that calls the function you need.


[#78505] Monday, April 29, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devonw

Total Points: 311
Total Questions: 116
Total Answers: 111

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
;