Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #16395 > unrolled thread
| Started by | justaguy <lichunshen84@gmail.com> |
|---|---|
| First post | 2012-10-04 12:46 -0700 |
| Last post | 2012-10-04 19:09 -0700 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.javascript
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
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2012-10-04 12:46 -0700 |
| Subject | How do we carry re-assignment element value? |
| Message-ID | <35097a25-2320-4fd0-ac26-bb2e2d310439@x14g2000yqh.googlegroups.com> |
When the form is submitted several times before its final submission.
<form>
<select id="delivery" name="delivery"
<option>a
<option>b
</form>
<input type="text" id="addNew" name="addNew">
row 1
row 2
...
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?
Thanks.
[toc] | [next] | [standalone]
| From | Danny <dann90038@gmail.com> |
|---|---|
| Date | 2012-10-04 15:57 -0700 |
| Message-ID | <39e4cafa-a6be-42d0-bc2a-ca9616580a08@googlegroups.com> |
| In reply to | #16395 |
Since I dunno specifically what you're doing, just an offhand guess is that, that so-called 'losing', I gather you mean you lose the selection made initially by the user from the list/select, that happens when you'd RESET or .reset() a form, it 'resets' to original defaults, one answer will be, DON'T reset it and just process whatever without having to do so. If you're asking for DATA PERSISTENCE, then you'd need to use either Cookies or localStorage or sessionStorage objects.
[toc] | [prev] | [next] | [standalone]
| From | JJ <jaejunks_at@_googlemail_dot._com> |
|---|---|
| Date | 2012-10-05 00:41 +0000 |
| Message-ID | <XnsA0E34ED072FE2jaejunksgooglemailco@0.0.0.44> |
| In reply to | #16395 |
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);
[toc] | [prev] | [next] | [standalone]
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2012-10-04 19:09 -0700 |
| Message-ID | <b4c949b5-606e-4e8e-88f8-d4ad0690c59a@v15g2000yqi.googlegroups.com> |
| In reply to | #16409 |
On Oct 4, 8:41 pm, JJ <jaejunks_at@_googlemail_dot._com> wrote:
> justaguy <lichunshe...@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);
Never mind. Problem solved. Thanks tho.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web