troubleshooting Question

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

Avatar of Wanting2LearnMan
Wanting2LearnManFlag for United Kingdom of Great Britain and Northern Ireland asked on
JavaScriptWeb DevelopmentPython
1 Comment1 Solution469 ViewsLast Modified:
I have the following code which adds a row to a html table when a button is pressed.

 $(table).append(
            '<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>'+
            '</tr>'
            ); 

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
                </table>

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

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.

Thanks
ASKER CERTIFIED SOLUTION
Bardobrave

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros