Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript onClick function doesn't work [duplicate]

<script language="javascript" type="text/javascript">
function delete() {
var newwindow;
newwindow=window.open();

}

function edit(){
}
</script>

[...]

   <table class="table table-striped">
      <thead>
      <th>Id</th>
      <th>Titel</th>
      <th>Ort</th>
      <th>Referenzcode</th>
      <th>Bearbeiten</th>
      <th>L�schen</th>
      </thead>
      <tbody>
          <c:forEach items="${vacancies}" var="vac">
          <spring:url value="/vac" htmlEscape="true" var="vacEdit" />
          <spring:url value="/vac/${vac.id}" htmlEscape="true" var="vacDelete" />
          <tr>
              <td><c:out value="${vac.id}"/></td>
              <td><c:out value="${vac.titel}"/></td>
              <td><c:out value="${vac.location}"/></td>
              <td><c:out value="${vac.referenceCode}"/></td>
              <td><input type="button" name="Bearbeiten" value="Edit" onclick="edit();"></td>
              <td><input type="button" name="Loeschen" value="Delete" onclick="delete();"></td>
          </tr>
          </c:forEach>
      </tbody>
  </table>

Google Chrome's JavaScript console throws out these three errors:

Uncaught SyntaxError: Unexpected token delete vacAdmin:23
Uncaught ReferenceError: edit is not defined  vacAdmin:122 
Uncaught SyntaxError: Unexpected token )    vacAdmin:123

Any suggestions why the onclick method doesn't call or find the edit() and delete() function?

like image 859
Stan Avatar asked Aug 30 '26 10:08

Stan


1 Answers

The problem is that you can't use reserved language words like delete as identifiers. In javascript delete is operator that removes object properties.

Rename you function to something like deleteVacancy this and it will work:

<input type="button" name="Loeschen" value="Delete" onclick="deleteVacancy();">
like image 179
dfsq Avatar answered Sep 01 '26 00:09

dfsq



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!