I was asked to validate our input fields. In that way I limited the characters you'll be able to fill in in an input field. My input field will increment whenever I add some data and I'm using one id for all.
It works on the first row but the rest it doesn't. Any suggestions how to fix it?
echo""
. "<form action=maintenance.php method=POST>"
. "<tr>"
. "<td><input class='textbox' type=text id='name' name=name value='" . $record['name'] . "'> </td>"
. "<td><input class='textbox' size=50 id='url' type=url name=url value='" . $record['url'] . "'></td>"
. "<td><textarea class=textbox rows=2 cols=50 wrap=physical id=desc name=desc>" . strip_tags($record['description']) . "</textarea></td>"
. "<input type=hidden name=hidden value='" . $record['name'] . "'>"
. "<td><button class='btn-style-icons shrink' type=submit name=update><img src=icons/update.png alt=Update></button></td>"
. "<td><button class='btn-style-icons shrink' type=submit name=delete><img src=icons/delete.png alt=Delete></button></td>"
. "</tr>"
. "</form>";
}
echo""
. "</table>"
. "<table>"
. "<form action=maintenance.php method=POST>"
. "<tr>"
. "<td><input class='textbox' id='name' type=text name=iname></td>"
. "<td><input class='textbox' id='url' size= 50 url=url name=iurl></td>"
. "<td><textarea class=textbox id=desc rows=2 cols=50 name=idesc></textarea></td>"
. "<td><button class='btn-style-icons shrink' type=submit name=add id=add><img src=icons/add.png alt=Add></button></td>"
. "</tr>"
. "</form>"
. "</table>";
This is how it looks like:

action.js
$(document).ready(function () {
$('#name').bind('keypress', function (event) {
var regex = new RegExp("^[a-zA-Z0-9 \b\t]+$");
var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
if (!regex.test(key)) {
event.preventDefault();
return false;
}
});
$('#url').bind('keypress', function (event) {
var regex = new RegExp("^[a-zA-Z0-9://. \b\t]+$");
var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
if (!regex.test(key)) {
event.preventDefault();
return false;
}
});
});
$(' #name').var regex = /^[a-zA-Z0-9 \b\t]+$/;- your regular expression won't work as it is because you didn't escape the backslashes.