Dave said:
Did you mean "Hello group"?
[...]
The select object's list is created (successfully) with a 'for' loop
in php using the following code:
Posting PHP code in a JS group is rather pointless, for you simply can
_not_ expect people to understand it. Especially, if you have a client-
side problem, post the client-side code, i.e. what is possibly being
generated by server-side code, first. However, as it happens I know myway
around PHP, too.
I agree that one can not, obviously, expect the people here to
understand php and as a result I only posted a single line from the
php code to display to everyone what was going to be parsed. This
would provide insight to anyone that offered to help to see what was
_actually_ being sent to the browser in its most "raw" form. It is a
very simple line of code that can be figured out easily. For anyone
that didn't understand it, I would have been more than happy to
explain it. Also using "possibly generated code" is not a good idea
as that can be were the problem lies and not in the code attempting to
be troubleshot, fixed, updated, etc.
print "<option value='$val'>".$name[0]." ".$name[1]." ".$name
[2]." ".$name[3]."</option>\n";
<OT>
There are a number of unnecessary concatenations here that make this harder
to read and potentially less efficient. In addition, you should not use
`print' unless you are interested in its constant return value 1 (as in an
expression).
I don't see the below code being any more "readable" than the one I
submitted, however, if you prefer to code it that way in an effort to
help find a solution, be my guest.
Also, all findings on echo vs
print say that the speed difference is marginal at best. This could
be opened for debate, however, this is the wrong place to do so. I do
appreciate the tidbit of info on the return value though.
echo "<option value='{$val}'>{$name[0]} {$name[1]}"
. " {$name[2]} {$name[3]}</option>\n";
(There are probably better ways to do this; printf() comes to mind.)
<
http://php.net/manual/en/function.print.php>
[...]
var aryName = document.getElementById('name1').options
[document.getElementById('name1').selectedIndex].text.split(/ /);
This can be optimized to
var o = document.getElementById('name1');
var aryName = o.options[o.selectedIndex].text.split(/ /);
Is this really optimized? Instead of parsing a single line of code, I
have to spend more resources and time assigning an object to a
variable, then processing the request. This might be another echo vs
print situation.
No, that is the _element's_ _ID_. However, if `name1' would be the
element's name (i.e., the value of its `name' attribute), you should
use the `elements' collection instead:
oops! You're right. I was a victim of saying one thing and thinking
another.
formRef.elements["name1"]...
I've tried using regular spaces and mixing the two, but can't figure this
out. The goal I'm after is that when the user clicks on a persons name
from the select object, their name (according to the value of the text)
is split and put into several text boxes that corresponds to the persons
first, middle, last, and suffix. I would greatly appreciate any helpon
resolving this problem.
` ' is an HTML character entity reference; it is the equivalent of
` ' (or  ). When it is parsed, it ends up as a single Unicode
(UCS-2, really) character in the parse tree, and, as a result, in the
document tree accessible with the DOM API. That is, ` ' is not
contained as such in the value of the `text' property (which you could have
found out by simply displaying it). Therefore, the split() method cannot
find it, and the return value is _a reference to an Array instance with
only one element_.
I did display it and you're right that was not in the output.
However, I did find that when using over a space character, I
was able to preserve the correct amount of spaces between the
different parts of the name so when it was parsed, the parts of the
names could be separated correctly. I also tried to use over a
regular space because what would happen if the person had two middle
names that wasn't hyphenated? Instead of there only being 4 parts to
the name (first, middle, last, suffix), now there would be 5. Now we
have a bug...
<
http://www.w3.org/TR/html401/sgml/entities.html>
To display Unicode characters in Unicode-supporting ECMAScript
implementations (of ES2 forward), you can include them verbatim or (better
here) you need to use an escape sequence, here `\u00A0'.
However, using ` ' does not make sense here in the first place if you
use ` ' as delimiter everywhere. I have yet to see a renderer that
word-wraps those entries (most notably FF's Gecko does not), so you can use
a space character instead. This would probably also help display as the
non-breaking space character is sometimes displayed narrower or wider than
the space character. And should there be a renderer that word-wraps the
value then in this case it appears to be better to encourage that than to
generate possibly incomplete display. You should use the `white-space:
nowrap' CSS declaration instead; if a renderer or user prefers different
display, they can easily overwrite (or ignore) that value.
In regards to not making sense as a delimiter, see the above
reply. In this situation, I'm not interested in word wrapping as the
text value is a value to an option in a select form object (which I've
never seen word wrapped options in a select/listbox/combobox). I most
likely will have to keep the or one of your afore mentioned
escape sequences so that the output to the user is normal (ie "first
middle last suffix" instead of something like
"first_middle_last_suffix"). Using &nsbp; (or an escape sequence)
provides the normal appearance while providing a character to split
the string correctly.
Dave
PS.
I did end up getting it to work in FF (haven't tested IE or Opera
yet) by keeping the in the print statement of the php code and
using the \u00A0 as the javascript split "character". Thanks for the
info on the escape codes! Can anyone see any issues with doing it
this way?