简体   繁体   中英

The for attribute of the label element must refer to a form control error?

This is driving me crazy. I know its something to do with the label tag. here is my code:

 <form method="post" action="includes/loginprocess.php">
    <label for="username">Username: </label>
    <input type="text" name="username" value=''/>

    <label for="password">Password: </label>
    <input type="password" name="password" />

    <input type="submit" name="submit" value="submit" />
</form>

The for and name are both the same?

The error is "The for attribute of the label element must refer to a form control."

According to http://www.w3schools.com/tags/att_label_for.asp , the value of for attribute of a label should be the id of the element the label is bound to, so add id attribute to the textboxes

<form method="post" action="includes/loginprocess.php">
    <label for="username">Username: </label>
    <input type="text" name="username" id="username" value=''/>

    <label for="password">Password: </label>
    <input type="password" name="password" id="password" />

    <input type="submit" name="submit" value="submit" />
</form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM