0

So, I'm working with a page that displays some links to specific people pages. I'm using a hyperlink to submit my forms. I have this code in a loop and am using the integer $position to give different ids to the multiple forms on the page.

Why does this work:

<form id="<? echo "Form" . $position;?>" method="post" action="../lecture">
<input type="hidden" name="personID" value="<? echo $indexstr;?>">
</form>
<a href="#" onclick="<? echo "Form" . $position ;?>.submit()"  ><? echo $firstname. ' ' . $lastname;?></a>

and this doesn't:

<form id="<? echo $position . "Form";?>" method="post" action="../lecture">
<input type="hidden" name="personID" value="<? echo $indexstr;?>">
</form>
<a href="#" onclick="<? echo $position . "Form" ;?>.submit()"  ><? echo $firstname. ' ' .   $lastname;?></a>

In case there was a problem with types and $position being an integer, I even tried converting it to a string before concatenating using strval(). The only difference is the order in which I concatenate "Form" and $position.

I really just want to understand. Thank you in advance for any responses I get.

insertusernamehere
  • 23,204
  • 9
  • 87
  • 126
  • You don't have to indicate edits in the post itself. A complete edit history of the post is available to everyone here: http://stackoverflow.com/posts/14655760/revisions. Your initial edit was within the 5 minute grace period, so it wasn't logged. – Robert Harvey Feb 01 '13 at 22:05

1 Answers1

4

An ID cannot start with a numeric character

http://www.w3.org/TR/html401/types.html#type-name

MDEV
  • 10,730
  • 2
  • 33
  • 49
  • Dang is that really it? D: *facepalm* Is there a reason why it's not allowed? –  Feb 01 '13 at 22:05
  • Probably because the language spec says so. In most languages, a numeric digit indicates the start of a numeric literal. – Robert Harvey Feb 01 '13 at 22:06
  • http://stackoverflow.com/questions/7987636/why-cant-i-have-a-numeric-value-as-the-id-of-an-element – Popnoodles Feb 01 '13 at 22:06
  • Added link to specification from answer noted by popnoodles – MDEV Feb 01 '13 at 22:09
  • Note that the HTML spec doesn't necessarily affect the ecmascript spec and vice versa. As of HTML5, ID attribute values *can* start with a number: http://mathiasbynens.be/notes/html5-id-class The issue is strictly with the javascript I presume. – Wesley Murch Feb 01 '13 at 22:11
  • Well thanks for your help guys. I would never have thought of that. I just assumed the naming conventions for the ID were the same as a regular variable. Definitely won't do that again.. –  Feb 01 '13 at 22:12