Form get operation truncating items with a space in them.

A

Atrus

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>\';

Thanks,
TIm
 
V

VK

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>\';

Did you try to match your quotes? They are all crewed. The string
assignment as posted cannot work at all. As you got some form
submission I assume you just grabbed a chunk of code from some
"innerHTML making innerHTML making innerHTML" Ruby-like code. Then a
workable example of your problem would be:

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>';

and the problem is then that your are not using quotes for the name
attribute so the parser gets
<input type="hidden" name="Name" value=hj hj>
so it rightfully assumes that the first "hj" is the attribute value
and the 2nd "hj" is an unknown tag attribute to disregard.
To fix your problem use quotes for values:
'<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>';
 
T

Thomas 'PointedEars' Lahn

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
 
A

Atrus

Okay, that fixed my problem, and I'll be sure to take into account all
your suggestions

Thanks!
 
M

Michael J. Ryan

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>\';

try escaping the name ('%20' or ' ')... or converting spaces to
underscores. As it is, it isn't a valid form field identifier.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top