Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #16409

Re: How do we carry re-assignment element value?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From JJ <jaejunks_at@_googlemail_dot._com>
Newsgroups comp.lang.javascript
Subject Re: How do we carry re-assignment element value?
Date Fri, 5 Oct 2012 00:41:02 +0000 (UTC)
Organization A noiseless patient Spider
Lines 33
Message-ID <XnsA0E34ED072FE2jaejunksgooglemailco@0.0.0.44> (permalink)
References <35097a25-2320-4fd0-ac26-bb2e2d310439@x14g2000yqh.googlegroups.com>
Injection-Date Fri, 5 Oct 2012 00:41:02 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="041275ad72822f875a187f1d67b21734"; logging-data="14849"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19gfTOTrhq7J4zaNAxsiOBv5dBzzq2l34c="
User-Agent Xnews/5.04.25
X-Face \*\`0(1j~VfYC>ebz[&O.]=,Nm\oRM{of,liRO#7Eqi4|!]!(Gs=Akgh{J)605>C9Air?pad{sSZ09u+A7f<^paR"/NH_#<mE1S"hde\c6PZLUB[t/s5-+Iu5DSc?P0+4%,Hl
Cancel-Lock sha1:uMv6qk+2d/DLO7pM3fFOicdIsVQ=
Xref csiph.com comp.lang.javascript:16409

Show key headers only | View raw


justaguy <lichunshen84@gmail.com> wrote:
> When the form is submitted several times before its final submission.

You lost me there. Once a form is submitted, it's final. A form can't be 
partially submitted.

> The idea of having the TEXT input field with id of "addNew" is to
> alllow user to add another value other than from the drop-down list.
> 
> js code:
>      var selObj = document.getElementById('delivery');
>           el = document.getElementById('addNew');
>           selObj.options[selObj.selectedIndex].value = el.value;
> 
> The code works.  However, this FORM is sent several times based on
> certain cell selection before Final Submission, what is happening now
> is on subsequent form submission (prior to Final Submission) we lose
> its re-assignment, namely,
> selObj.options[selObj.selectedIndex].value = el.value;
> How do we circumvent this problem?

That code replace the item value that's currently being selected, instead 
of adding a new one. To add a new item selection (new OPTION tag), use 
this:

//create new OPTION element
var el = document.createElement('OPTION');
//set the value
el.value = document.getElementById('addNew').value.trim();
//set the display text (for display only; optional)
el.textContent = document.getElementById('addNew').value.trim();
//append the new OPTION element into "delivery" selector
document.getElementById('delivery').appendChild(el);

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How do we carry re-assignment element value? justaguy <lichunshen84@gmail.com> - 2012-10-04 12:46 -0700
  Re: How do we carry re-assignment element value? Danny <dann90038@gmail.com> - 2012-10-04 15:57 -0700
  Re: How do we carry re-assignment element value? JJ <jaejunks_at@_googlemail_dot._com> - 2012-10-05 00:41 +0000
    Re: How do we carry re-assignment element value? justaguy <lichunshen84@gmail.com> - 2012-10-04 19:09 -0700

csiph-web