0

I have an HTML assignment. Here's the task...

[make something that] has:

  • an single-line text input with an id of "name",
  • a name of "pet_name",
  • and with an associated label that reads "Name".

I thought I had the right code, but it's saying I got it wrong and this was the feedback I got:

has exactly one input with a name of 'pet_name' and an associated label with the content 'Name'.

This is the HTML code that I had:

<label for="name">Name</label>
<input type="text" id="name" name="pet_name">

Could someone please help me identify what I'm doing wrong?

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
Elijah
  • 31
  • 3
  • Hi, EHubb! Welcome to SO! Your code looks fine, I made a [jsbin demo](https://jsbin.com/bupiwoy/edit?html,output), clicking the "Name" label causes the field to be highlighted, which is correct behavior. My only thought is the proofing may be broken? I'm not sure. – HoldOffHunger Jun 04 '20 at 17:17
  • 1
    Hi, EHubb! I'm stumped! Your code is fine. Where are you validating this/having it checked? Maybe try wrapping it all in a `
    ...
    ` in one line? Maybe it wants a very specific format, i.e., ``? Let me know, I have no idea.
    – HoldOffHunger Jun 04 '20 at 17:24
  • Yea that's what I was thinking too. It's an assignment for app academy. When I submit the html file, it goes thru it to see if I have all the right code. I'll ask my advisor about it. Cause I don't see anything wrong either. Thank you for you help! – Elijah Jun 04 '20 at 17:40
  • No problem! If one of those suggestions works, let me know and I can post an answer or something! – HoldOffHunger Jun 04 '20 at 17:42
  • If I originally had for="Name" with the "N" being a capital letter, would that be wrong? – Elijah Jun 04 '20 at 17:48
  • It probably would have been wrong, [id's in javascript are case-sensitive](https://stackoverflow.com/q/1236856/2430549). – HoldOffHunger Jun 04 '20 at 17:56

2 Answers2

0

You have to change name="name" Because for and name both the property have to match.

Dharmik Patel
  • 1,041
  • 6
  • 12
0

The for attribute of the label tag has to match the id attribute of the input tag it's describing. So in your case, it should be <label for="name">Name</label>.

The name attribute of the input tag is only relevant for sending the values / receiving them after submission of the form.

See also: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label

Johannes
  • 64,305
  • 18
  • 73
  • 130