Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7830369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:12:21+00:00 2026-06-02T11:12:21+00:00

I have this code: function addFormControls() { var e = document.getElementById(ProductsList); var prodid =

  • 0

I have this code:

function addFormControls() {
    var e = document.getElementById("ProductsList");
    var prodid = e.options[e.selectedIndex].value;
    var prodvalue = e.options[e.selectedIndex].text;
    if (num == 0) {
        document.getElementById("ProductsPanel").innerHTML = '<h3>Products added to Variant</h3>';
    }
    if (num < 10) {
        var boolCheck = checkArrayData(prodid);
        if (boolCheck == false) {
            document.getElementById("ProductsPanel").innerHTML = document.getElementById("ProductsPanel").innerHTML + prodvalue + '<input type="text" id="' + prodid + 'product" value="0" width="50px" maxlenght="2" /><input type="button" onclick="updateArrayData(\'' + prodid + '\', document.getElementById(\'' + prodid + 'product\').value);" value="Update Number" /><br />';
            num++;
            prodIdArray.push({
                'key': prodid,
                'value': prodvalue,
                'num': 0
            });
            document.getElementById("productsArray").value = prodIdArray;
        } else {
            alert("Sorry product has already been added!");
        }
    }
}

which happily updates a div tag with new info, however if you look at the section where it prints a text box to the screen, line 13, these textbox’s will be updated by the user.

So in short, textboxs are added, and value update.

however if there is a textbox with value 5, then this function called again to add another textbox, the previous textbox’ values will be wiped clean!

So, how do i prevent this, will i have to do some, for loop over div controls taking the values, then put them back after this function is called?!?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T11:12:22+00:00Added an answer on June 2, 2026 at 11:12 am

    I create some javascript to save all the values in a particular input’s value field before adding the control, then return all the saved values back to their respected inputs.

        function saveValuesOfProducts()
    {
        // initialise the array
        numOfProds = new Array();
        // get all the elements which are inputs
        var x=document.getElementsByTagName("input");
        // remove all un necessary inputs
        x = leaveTextInputs(x);
        // loop through the entire list of inputs left saving their value
        for (i=0; i<x.length; i++)
        {
            numOfProds.push(x[i].value);
        }
    }
    function returnValuesOfProducts()
    {
        // get all the elements which are inputs
        var x=document.getElementsByTagName("input");
        // remove all un necessary inputs
        x = leaveTextInputs(x);
        // loop through the entire list of saved values and return them to the input
        for (i=0; i<numOfProds.length; i++)
        {
            x[i].value = numOfProds[i];
        }
    }
    
    function leaveTextInputs(value)
    {
        // create a new blank array
        var newArr = new Array();
        // loop through all the elements in passed array
        for (i=0; i<value.length; i++)
        {
            // cache the element
            var thevalue = value[i];
            // check if the element is a text input
            if (thevalue.type == "text")
            {
                // check the id consists of product in it!
                var regexteststring = thevalue.id;
                // create the pattern to match
                var patt1 = /product/i;
                if (regexteststring.match(patt1) == "product")
                {
                    // as additional check, if it has a size quantity of 2 then its defo out stuff
                    if (thevalue.size == 2)
                    {
                        newArr.push(thevalue);
                    }
                }
            }
        }
        // now return the new array
        return newArr;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of code: function func1(text) { var pattern = /([\s\S]*?)(\<\?(?:attrib |if
I have this code in jquery : $(#order_btn).click(function(){ var totalprice = $(.price_amount).text(); $(#totalprice).val(totalprice); });
I have this code: function render(str) { var main = document.createElement('div'); with(main.style) { //style
I have this code : function move() { $(document).mousemove(function(e){ var x = e.pageX; $('.linkHover').animate({'right':
I have this code function getSelectData(id) { jQuery(id).change(function () { var value=''; jQuery(id+ option:selected).each(function
I have this code: _trackit: function(){ for(var key in this.items.sublinks){ switch(key){ case 'shoes': for(var
I have this code: (function ($) { $(document).ready(function() { test(hola,caracola); }); function test(somevar1, somevar2)
I have this code var stats = { GetMetaData : function() { var url
i have seen this code: Function.prototype.bind = function (bind) { var self = this;
I have this code: function getTime(zone, success) { var url = 'http://json-time.appspot.com/time.json?tz=' + zone,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.