RcBuilder@walla.com
call centre: 054-5614020

option javascript class

09
Nov
2014
Posted by: RcBuilder  /   Category: append / Array / HTML / JAVASCRIPT / jQuery / onchange / select   /   No Comments

option javascript class

OPTION CLASS

function option(text, value) {
this.text = text;
this.value = value;

this.toTag = toTag;

function toTag() {
return ‘<option value=”‘ + this.value + ‘”>’ + this.text + ‘</option>’;
}
}

HTML

<select id=”cmbMaster” onchange=”LoadSlaveCombo(this.value);” style=”width:130px;”>
<option value=”males”>males</option>
<option value=”females”>females</option>
</select>
<select id=”cmbSlave” style=”width:130px;”></select>

USING

// two levels selects
// fill slave combo refer to master combo selection
var arr_names = new Array();
arr_names['males'] = [
new option('Roby', '111'),
new option('Avi', '222'),
new option('Ron', '333'),
new option('Isaac', '888'),
new option('Bonnie', '999'),
new option('Oren', '666'),
new option('Eran', '1010'),
new option('Slava', '1313')
];

arr_names['females'] = [
new option('Galit', '1414'),
new option('Yardena', '444'),
new option('Shirly', '1212'),
new option('Sharona', '1515'),
new option('Shulamit', '777'),
new option('Ofra', '1111'),
new option('Yehudit', '555')
];

function LoadSlaveCombo(type) {
var cmb = $(‘#cmbSlave’);
var arr = arr_names[type];

cmb.empty();
for (var n = 0; n < arr.length; n++)
cmb.append(arr[n].toTag());
}

$(document).ready(function () {
LoadSlaveCombo(‘males’);
});

Author Avatar

About the Author

בניית אתרים ופתרונות טכנולוגים | RcBuilder

No Comments


  • פיתוח מערכות
  • פתרונות טכנולוגים
  • קידום אתרים
  • בניית אתרים