DanielST
DanielST

Reputation: 14133

Can't call JavaScript functions

The page source:

<html>
<head>
<title>Admin Search Results</title>

<script type="text/javascript">
function delete()
{     
    alert("abc");
}
</script>
</head>
<body>
<h1>Admin Search Results</h1>
<form id="modDel" action="modDel.pl" method="post" onsubmit="return delete()">
<table border="1">
<tr>
<th>User Name</th>
<th>Email</th>
<th>First Name</th>
<th>Last Name</th>
<th>Password</th>
<th>Blocked</th>
<th>Modify</th>
<th>Delete</th>
</tr>
<tr>
<input type="hidden" id="un_0" name="un_0" value="aa">
<td>aa</td>
<td>aa</td>
<td>aa</td>
<td>aa</td>
<td>aa</td>
<td>0</td>
<td><input type="submit" name="modify_0" value="Modify"></td>
<td><input type="checkbox" id="delete_0" name="delete_0" value="Yes"></td>
</tr>
<tr>
<input type="hidden" id="un_1" name="un_1" value="a">
<td>a</td>
<td>a</td>
<td>a</td>
<td>a</td>
<td>a</td>
<td>0</td>
<td><input type="submit" name="modify_1" value="Modify"></td>
<td><input type="checkbox" id="delete_1" name="delete_1" value="Yes"></td>
</tr>

</table>
<input type="hidden" id="count" name="count" value="1">
<input type="submit" id="delete" name="delete" value="Delete Selected Accounts" onclick="delete()">
<button type="button" onclick="delete()">Display Date</button>
</form>
</body>
</html>

It's generated by a Perl script from two templates (one for the table).

All I want is to get something to happen on some event. I've added onsubmit and onclick but neither work.

I'm sure I'm just missing something small but I can't see it. I'm using Chrome, BTW.

Edit: I can get it to work by adding the js code directly into the onclick/onsubmit quotes.

Upvotes: 0

Views: 3366

Answers (1)

JaredPar
JaredPar

Reputation: 754715

The problem here is that delete is a reserved word in JavaScript. Try a different function name. Also there is no need for the return in the onsubmit function, just invoke the function directly.

<script type="text/javascript">
function deleteFunc()
{     
    alert("abc");
}
</script>
</head>
<body>
<h1>Admin Search Results</h1>
<form id="modDel" action="modDel.pl" method="post" onsubmit="deleteFunc()">

Upvotes: 3

Related Questions