Avatar of Wanting2LearnMan
Wanting2LearnManFlag 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.

 $(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>'
            ); 

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

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.

Thanks
JavaScriptPythonWeb Development

Avatar of undefined
Last Comment
Bardobrave
ASKER CERTIFIED SOLUTION
Avatar of Bardobrave
Bardobrave
Flag of Spain image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo