Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid location of HTML tag

I am trying to make a simple form using HTML and Servlets. Everything is set, but I am getting a yellow underline in my HTML markup. It says: Invalid location of tag (input) , where I am trying to implement the form in my HTML.

My code looks good and I don't see the problem. What am I doing wrong?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="style.css" />
    <title>Projektuppgift1</title>
</head>
<body>
    ...
    // This is where I am getting the error
    <form action="LoginServlet" method="post">
        username: <input type="text" name="name" />
        password: <input type="password" name="password" />
        <input type="submit" value="submit" />
    </form>
    ...
</body>
</html>
like image 609
Smile Avatar asked Sep 28 '22 19:09

Smile


1 Answers

The form tag may only contain block elements is XHTML Strict, so neither <span> nor <input> is valid. You can wrap it in a <div> though, then it is fine.

For example:

<form action="LoginServlet" method="post">
    <div>Username: <input type="text" name="name" /></div>
    <div>Password: <input type="password" name="password" /></div>
    <div><input type="submit" value="submit" /></div>
</form>

However I would advise against using XHTML, it is a thing of the past, and has some serious drawbacks too (e.g. IE8 does not support it at all, and unfortunately some people still have to use this). You should use HTML5, it also has an XML serialization.

like image 55
meskobalazs Avatar answered Oct 03 '22 01:10

meskobalazs