You are using an outdated browser. Please upgrade your browser to improve your experience and security.

JavaScript onClick function not working

<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 JavaScript Console throws 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 method onclick

doesn't call or find the function edit()

and delete()

?

+3
javascript html web


source to share


1 answer


The problem is that you cannot use language reserved words delete

like identifiers. In javascript, it delete

is an operator that removes the properties of an object.

Rename the function to something like this deleteVacancy

and it will work:



<input type="button" name="Loeschen" value="Delete" onclick="deleteVacancy();">

      

+4


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics