<!DOCTYPE html>
<html>
<head>
<script>
function XSSPrevent(){
var usercomments = document.getElementById('usertext').value;
if(usercomments.contains("<script>"){
alert("Failed");
} else
alert("Thank you for your comments" + usercomments);
}
</script>
</head>
<body>
<form>
<input type="text" id="usertext" maxlength=50/>
<input type="submit" value="Enter" onclick="XSSPrevent()"/>
</form>
</body>
It is my first time to work with both HTML form and javascript. Console
shows an unexpected token { after if loop. What's wrong?
I know it is not a good idea to use an alert method in this situation but I
just wanna check my function quickly.