简体   繁体   中英

Alert box doesn't display anything

The JSP is:

<input type="submit" value="GENERATE TICKET" class="button" name="generate" onclick="myFunction()">
<script>
function myFunction() {
    alert(
    <%SelectCustomer sc = new SelectCustomer();
    System.out.println(sc.getCash());%>
    );
}
</script>

The java class is:

public class SelectCustomer
{
    public int getCash() throws SQlException
    {
        return 12;
    }
}

The alert box pops but is blank. What is the reason? How to print 12 in the alert box?

Try using <%= %> instead of <% %> .

Also make sure you are using quotes inside of your alert function call.

try this code add an input hidden were you put the wanted value

<input type='hidden' name='' id='data' value=' <%= VALUE-HERE  %>' />

Then JS :

var content =document.getElementById('data').getAttribute('value');
alert(content);

Please try with this script:

<script>
function myFunction() {
    <%  Windowlogin sc = new Windowlogin();%>   
        alert(<%=sc.getCash()%>);   
}
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM