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 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: 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_# 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);