Special Thanks to Mahmudul and Md. Mutaherul Islam ( Babu )
The reply was quick and the solution worked for me very well.
Regards,
Rahat Bashir
On Mon, May 30, 2011 at 8:28 PM, Md. Mahmudul Hasan <mukul_cse_ruet@yahoo.com> wrote:
Hello Rahat Bashir,
Adjust your array elements like below and try the following code:
<script type="text/javascript">
$(document).ready(function(){
var mylist = new Array(5);
for (var i = 0; i < mylist.length; i++) {
mylist[i] = new Array(2);$.each(mylist,function( index, objVal ){
}
mylist[0][0] = 'value1';
mylist[0][1] = 'value11';
mylist[1][0] = 'value2';
mylist[1][1] = 'value22';
mylist[2][0] = 'value3';
mylist[2][1] = 'value33';
mylist[3][0] = 'value4';
mylist[3][1] = 'value44';
mylist[4][0] = 'value5';
mylist[4][1] = 'value55';
$('select[name="myselect"]').append($('<option></option>').val(objVal[0]).html(objVal[1]));
});
});
</script>
Make sure that you have a dropdownlist element with name="myselect" inside your html body tag.
Like:
<select name="myselect" ></select>
Good Luck.
-MahmudulSent: Mon, May 30, 2011 4:23:25 PM
Subject: [phpXperts] Need help for js array
Hello Experts,
I am a new user of jquery. Can anyone help me solving the following:
I have the following javascript array:
var mylist = new Array();
mylist[0][0] = 'value1';
mylist[0][1] = 'value11';
mylist[1][0] = 'value2';
mylist[1][1] = 'value22';
mylist[2][0] = 'value3';
mylist[2][1] = 'value33';
mylist[3][0] = 'value4';
mylist[3][1] = 'value44';
mylist[4][0] = 'value5';
mylist[4][1] = 'value55';
I want to populate options of a select element with these values with jquery, like below:
<select name="myselect">
<option value="value1">value11</option>
<option value="value2">value22</option>
<option>...........
</select>
I tried $.each(), but could not make it.
Regards,
Rahat Bashir
__._,_.___
Visit phpXperts website at www.phpxperts.net
MARKETPLACE
.
__,_._,___
No comments:
Post a Comment