Atrus said:
With the below, name has a value of "hj hj", however whenever I click
the "Remove Me" button, it only sends the first hj. Why is this?
x.innerHTML = \'<form action="/remove" method="get"><input
type="submit" value="Remove Me"/><input type="hidden" name="Name"
value=\' + name + \'><input type="hidden" name="Unique" value=\' +
unique + \'></form>\';
(Assuming this is a snippet of unnecessarily inefficient written server-side
code that is supposed to generate weird HTML markup that is error-corrected
later client-side: )
That only the first `hj' is written is because you have not delimited the
value of the `value' attribute. Assuming that the client-side value of
`unique' is "foo", the above will generate
<form action="/remove" method="get"><input type="submit" value="Remove
Me"/><input type="hidden" name="Name" value=hj hj><input type="hidden"
name="Unique" value=foo></form>
Therefore, the second `hj' is considered an (invalid) attribute name.
Change into
x.innerHTML = '<form action="/remove"><input type="submit" value="Remove
Me"><input type="hidden" name="Name" value="' + name + '"><input
type="hidden" name="Unique" value="' + unique + '"><\/form>';
employing whatever means available at your server for putting out the
client-side code without previous server-side parsing (in PHP:
`?>...<?php'), making the server-side code easier to maintain.
That said, you SHOULD avoid the proprietary `innerHTML' property, and you
MUST avoid it with XHTML (as indicated by the NET-enabled start tag of the
`input' element); build the document subtree using W3C DOM Level 2+ methods
instead.
In addition, having a form control named `name' (or case-folded variations
thereof), and a global variable `name', can lead to undesired side effects:
`name' is both the name of a property of Window objects and of form objects.
PointedEars