Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onClick javascript not working

Tags:

javascript

I can't get a javascript inline function call to work. The inline function is this:

<span> <input type="button" value="Previous Week" onClick="subtractOneWeekReloadPage()"> 

I have the function that should be called written into the header as follows:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Time Tracking Page</title>

<script type="text/javascript">
function subtractOneWeekReloadPage() {
<%=currentWeek.subtractOneWeek()%>;
window.location.reload();}

</script>

</head>

When I click on the button on the web page nothing happens though. Neither my jsp call nor the page refresh call is running. Can anyone tell me what I'm doing wrong please?

The relevant output of the page is:

<span> 
<input type="button" value="Previous Week" onClick="subtractOneWeekReloadPage()"> 
Hours for the week of 
<%=currentWeek.firstDayOfThisWeek()%> 
until 
<%=currentWeek.lastDayOfThisWeek()%> 
<input type="button" value="Next Week" onClick="addOneWeekReloadPage()">
</span>

The jsp calls to display the first and last days of the week are working fine. But when I click to subtract one week and reload the page with the newly set week, nothing is happening.

like image 400
CorayThan Avatar asked Mar 08 '26 00:03

CorayThan


1 Answers

The JSP has already run before the page even gets to the browser. If currentWeek.subtractOneWeek outputs anything other than valid JS code, you get a syntax error and the code refuses to run.

like image 78
Niet the Dark Absol Avatar answered Mar 09 '26 14:03

Niet the Dark Absol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!