From: MC on

"David Mark" <dmark.cinsoft(a)gmail.com> wrote in message
news:hksrtg$kah$1(a)news.eternal-september.org...
> MC wrote:
>> "David Mark" <dmark.cinsoft(a)gmail.com> wrote in message
>> news:hksq8a$6ho$1(a)news.eternal-september.org...
>>> MC wrote:
>>>> "David Mark" <dmark.cinsoft(a)gmail.com> wrote in message
>>>> news:685a01f4-502a-4829-9f5f-04791fbef3a9(a)f15g2000yqe.googlegroups.com...
>>>>> On Feb 9, 2:14 pm, "MC" <mica[removethis]@aisus.com> wrote:
>>>>>> "David Mark" <dmark.cins...(a)gmail.com> wrote in message
>>>>>>
>>>>>> news:fae9c4d0-11b6-46ec-a448-a202172ff873(a)b18g2000vba.googlegroups.com...
>>>>>>
>>>>>>
>>>>>>
>>>>>>> On Feb 9, 1:57 pm, "MC" <mica[removethis]@aisus.com> wrote:
>>>>>>>> "David Mark" <dmark.cins...(a)gmail.com> wrote in message
>>>>>>>> news:be291d52-360d-464e-9f26-4e8b612e368d(a)a13g2000vbf.googlegroups.com...
>>>>>>>>> On Feb 9, 1:20 pm, "MC" <mica[removethis]@aisus.com> wrote:
>>>>>>>>>> David Mark, my favorite javascript guy!
>>>>>>>>> Hey!
>>>>>>>>>> Yes, I am trying to get the user input from checkbox, radio,
>>>>>>>>>> input,
>>>>>>>>>> and
>>>>>>>>>> select.
>>>>>>>>> There are inputs, selects and textareas (checkbox and radio are
>>>>>>>>> _types_ of inputs).
>>>>>>>>>> It seems the input is retrieved via innerHTML but the other is
>>>>>>>>>> not.
>>>>>>>>> The results of that proprietary property are implementation
>>>>>>>>> dependant. You will have to traverse the DOM and use the checked,
>>>>>>>>> value and selectedIndex properties to determine the states of the
>>>>>>>>> form
>>>>>>>>> controls. It sounds as if the browsers you tested were
>>>>>>>>> referencing
>>>>>>>>> the defaultChecked and defaultSelected properties for
>>>>>>>>> radio/checkbox
>>>>>>>>> inputs and select options, but not the defaultValue property for
>>>>>>>>> text
>>>>>>>>> inputs. That's certainly an incongruous approach.
>>>>>>>>> Also, if you must deal with multi-selects, there is no single
>>>>>>>>> property
>>>>>>>>> to reference (you have to loop through the options and check the
>>>>>>>>> selected property for each).
>>>>>>>>> And I've got to ask, what is the purpose of this? Seems like a
>>>>>>>>> can
>>>>>>>>> of
>>>>>>>>> worms that doesn't need to be opened.
>>>>>>>>> Please don't top-post. It screws up the context of the dicussion
>>>>>>>>> (and
>>>>>>>>> I don't care to restore it).
>>>>>>>> Purpose: Document a page into an archive (with user input) via
>>>>>>>> ajax.
>>>>>>>> These
>>>>>>>> pages are basically user forms that are then sent to a document
>>>>>>>> archive
>>>>>>>> service. Without the user input, archival is useless.
>>>>>>> Deja vu. Haven't we had this discussion before?
>>>>>>> Personally, I would serialize the data without the markup. ;)
>>>>>> We have and I didn't find an answer. Prior to this, the archival
>>>>>> software
>>>>>> was not finished. The archival software is now complete and working
>>>>>> like
>>>>>> a
>>>>>> champ turning html into beautiful pdf exactly like the html form. So
>>>>>> now
>>>>>> the
>>>>>> project is going live and I need to resolve this last issue.
>>>>> You will have to traverse the form and build the HTML string yourself
>>>>> as innerHTML is not an appropriate format to store (varies from one
>>>>> browser to the next). Have you tried to do that? If you only need
>>>>> form controls, it is fairly trivial. First define what sort of form
>>>>> controls will be involved (e.g. what about textareas?)
>>>>>
>>>>> Start with something like this:-
>>>>>
>>>>> function serializeFormHtml(name) {
>>>>> var el = document.forms[name];
>>>>> var control, controls = el.elements;
>>>>> var result = [];
>>>>>
>>>>> for (var i = controls.length; i--;) {
>>>>> control = controls[i];
>>>>> switch (control.tagName.toLowerCase()) {
>>>>> case 'input':
>>>>> ...
>>>>> break;
>>>>> case 'select':
>>>>> ...
>>>>> break;
>>>>> case 'textarea':
>>>>> ...
>>>>> break;
>>>>> }
>>>>> }
>>>>>
>>>>> return result.join('');
>>>>> }
>>>>>
>>>>> You will have to fill in the blanks as only you know the context of
>>>>> your application. For example, other than name and value; what, if
>>>>> any, attributes should be included? Will there be multi-selects, do
>>>>> you care about disabled controls, etc.?
>>>> All of those controls will be dealt with. We are not storing html but
>>>> converting html into a pdf representation and it is pretty exact. Its
>>>> actually really cool, as users go about their day, their work is
>>>> automatically e-archived via ajax, saving them a huge amount of
>>>> time/money
>>>> printing and filing.
>>> As RobG mentioned, this task is better suited for the server.
>>>
>>>> What about this? It seems to work.
>>> Those are typically famous last words. :)
>>>
>>>> while (e = oForm.elements[i++]) {
>>> I don't care for that style (it raises the question of whether it was
>>> supposed to be two equal signs).
>>>
>>>> if (e.type == 'checkbox') {
>>>> if (e.checked == true) {
>>> if (e.checked) {
>>>
>>> The rest is superfluous.
>>>
>>>> e.defaultChecked = true;
>>>> } else {
>>>> e.defaultChecked = false;
>>>> }
>>>> }
>>> Here you have set the attribute, which _should_ show up in the
>>> innerHTML.
>>>
>>>> if (e.type == 'radio') {
>>>> var x = e.name;
>>> Why?
>>>
>>>> if (e.checked == true) {
>>> See above.
>>>
>>>> e.defaultChecked = true;
>>>> } else {
>>>> e.defaultChecked = false;
>>>> }
>>>> }
>>>> }
>>> Seems redundant other than the unused - x - variable, but you have the
>>> basic idea.
>>>
>>> But what about the selects? This is all leading to a much simpler
>>> server-side solution.
>>
>> Your right, here it is refactored. Still in working on the select.
>> function processFormData(oForm) {
>> var e, i = 0;
>> while (e = oForm.elements[i++]) {
>> if (e.type == 'checkbox' || e.type == 'radio') {
>> if (e.checked == true) {
>> e.defaultChecked = true;
>> } else {
>> e.defaultChecked = false;
>> }
>
> Why not just:-
>
> e.defaultChecked = e.checked;
>
>> }
>> if (e.type == 'select') { // working on this
>
> Loop through the options, set defaultSelected to match selected for each.

David...

This is why your my favorite JS expert :) You offer great tutilage without
judgement. I did this because there might be an initial default in code and
this will remove it.

Thank you!!!!
MC
PS. Don't tell pointy ears, but I vote you #1...I can't stand to hear his
ranting


From: David Mark on
MC wrote:

[...]

>>> if (e.type == 'select') { // working on this
>> Loop through the options, set defaultSelected to match selected for each.
>
> David...
>
> This is why your my favorite JS expert :)

Glad I could help!

> You offer great tutilage without
> judgement.

I try.

> I did this because there might be an initial default in code and
> this will remove it.

Yes, it will clobber all of the defaults (as you wanted).

>
> Thank you!!!!
> MC
> PS. Don't tell pointy ears, but I vote you #1...I can't stand to hear his
> ranting
>
>

It's not really a contest, but thanks for your support!