Avatar of Wanting2LearnMan
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Adding values from javascript array to a dropdown box in an html table.

I have the following code which adds a row to a html table when a button is pressed.

            '<tr><td><input  class="SettingsListField save_pending" type="text" ' +
            'id="' + $(this).attr('id') + '_' + newIndex + '" name="' + $(this).attr('id') + '"></td>'+
            '<td><input  class="SettingsListField save_pending" type="text" ' +
            'id="' + $(this).attr('id') + '_' + newIndex + '" name="' + $(this).attr('id') + '"></td>'+
	    '<td><select class="CustomSelect1 not_changed" id="' + $(this).attr('id') + '_' + newIndex + '" name="' + $(this).attr('id') + '"> <option>"item1"</option>></td>'+
            '<td><div class="SettingsIconContainer"><a class="InputListbtnRemove" onclick="return false;">'+
            '<img src="/static_media/img/RemoveButton2_small.png" alt="Remove address details" /></a></div></td>'+
            '<td><div class="SettingsStatusContainer" id="' + $(this).attr('id') + '_' + newIndex + '_status"></div></td>'+

Open in new window

I want to modify the line that adds the list box so that it iterates through an array of variables passed to it.

1. First I need to know how to pass this array from the html page to the javascript page.
I am using python on a django framework and I can pass a string variable like so:
On my html page:
 <div id="myDiv" max_list_length="{{ myPythonVaribale }} ">
                <table> blah blah

Open in new window

On my javascript page I access this variable like so:
var MaxListLength = document.getElementById("myDiv").getAttribute("max_list_length");

Open in new window

2. Secondly I need to know how to modify above code that creates the table to add each element in the array to the dropdown box.

JavaScriptPythonWeb Development

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck