i writing a code to create select box
[CODE=javascript]function getSelectBoxDOM (options,nm) {
selectBox =document.creat eElement('selec t');
for (x=0; x < options.length; x++) {
optionItem =document.creat eElement('optio n');
optionItem.appe ndChild(documen t.createTextNod e(options[x]));
selectBox.appen dChild(optionIt em);
}
selectBox.setAt tribute("name", nm);
selectBox.setAt tribute("id",nm );
s=new function(){}
selectBox.oncha nge =new function() {
showmcode(this. options[this.selectedIn dex].value);
}
return selectBox;
}[/CODE]
which is called here
[CODE=javascript] function create_object(o bjType,nm){
if(objType == 'select'){
return getSelectBoxDOM (select_opt,nm) ;
//select_opt.onch ange = function() {
// showmcode(this. options[this.selectedIn dex].value);
// }
}
obj = document.create Element("input" );
obj.setAttribut e("type",objTyp e);
obj.setAttribut e("name",nm);
obj.setAttribut e("id",nm);
return obj;
}[/CODE]
and when i'm adding rows the function create_object is called
[CODE=javascript]function add_rows(obj){
//tabObj = document.create Element("table" );
//tbodyObj = document.create Element("tbody" );
tabCols = new init_table();
trObj = document.create Element("tr")
col_names = new Array("chk","m_ cde","m_name"," um","qty","over ages");
for(i=0;i<tabCo ls.length;i++){
tdObj = document.create Element("td");
tdObj.appendChi ld(create_objec t(tabCols[i],col_names[i]+'['+j+']'));\
tdObj.appendChi ld(op.value);
trObj.appendChi ld(tdObj);
}
obj.firstChild. appendChild(trO bj);
j++;
}[/CODE]
and in test.php i'm assigning values to options
so when the form is loaded select options are filled with database values
[PHP]<?
$sqlmaterial="s elect * from materialmaster order by m_cde";
$db_query_mater ial=$DB_site->query($sqlmate rial);
while($rsmateri al=$DB_site->fetch_array($d b_query_materia l)){
$option_vals[]=$rsmaterial['m_cde']."-".$rsmateri al['m_name'];
}
?>
<script>
select_opt = new Array();
<?
for($i=0;$i<cou nt($option_vals );$i++){
?>
select_opt[<?= $i ?>] = '<?= $option_vals[$i] ?>';
<?
}
?>[/PHP]
now how and where to writea code to give onchange event to the select box
i tried create_object function where objtype="select " and where getselectbox function is called but same error.
i also tried in addrow function just after creating object ..
i'm new to ajax and dom
so please tell me how do do this
i have a static row where the same m_cde select box is there where this function is working prooerly
but when i do it for dynamic rows if i alert then it shows [object]
and with static rows it shows the allthe object created with id and all
also how do i pass the m_cde as arry to the url inthe showmcode function for rows .
thanks
[CODE=javascript]function getSelectBoxDOM (options,nm) {
selectBox =document.creat eElement('selec t');
for (x=0; x < options.length; x++) {
optionItem =document.creat eElement('optio n');
optionItem.appe ndChild(documen t.createTextNod e(options[x]));
selectBox.appen dChild(optionIt em);
}
selectBox.setAt tribute("name", nm);
selectBox.setAt tribute("id",nm );
s=new function(){}
selectBox.oncha nge =new function() {
showmcode(this. options[this.selectedIn dex].value);
}
return selectBox;
}[/CODE]
which is called here
[CODE=javascript] function create_object(o bjType,nm){
if(objType == 'select'){
return getSelectBoxDOM (select_opt,nm) ;
//select_opt.onch ange = function() {
// showmcode(this. options[this.selectedIn dex].value);
// }
}
obj = document.create Element("input" );
obj.setAttribut e("type",objTyp e);
obj.setAttribut e("name",nm);
obj.setAttribut e("id",nm);
return obj;
}[/CODE]
and when i'm adding rows the function create_object is called
[CODE=javascript]function add_rows(obj){
//tabObj = document.create Element("table" );
//tbodyObj = document.create Element("tbody" );
tabCols = new init_table();
trObj = document.create Element("tr")
col_names = new Array("chk","m_ cde","m_name"," um","qty","over ages");
for(i=0;i<tabCo ls.length;i++){
tdObj = document.create Element("td");
tdObj.appendChi ld(create_objec t(tabCols[i],col_names[i]+'['+j+']'));\
tdObj.appendChi ld(op.value);
trObj.appendChi ld(tdObj);
}
obj.firstChild. appendChild(trO bj);
j++;
}[/CODE]
and in test.php i'm assigning values to options
so when the form is loaded select options are filled with database values
[PHP]<?
$sqlmaterial="s elect * from materialmaster order by m_cde";
$db_query_mater ial=$DB_site->query($sqlmate rial);
while($rsmateri al=$DB_site->fetch_array($d b_query_materia l)){
$option_vals[]=$rsmaterial['m_cde']."-".$rsmateri al['m_name'];
}
?>
<script>
select_opt = new Array();
<?
for($i=0;$i<cou nt($option_vals );$i++){
?>
select_opt[<?= $i ?>] = '<?= $option_vals[$i] ?>';
<?
}
?>[/PHP]
now how and where to writea code to give onchange event to the select box
i tried create_object function where objtype="select " and where getselectbox function is called but same error.
i also tried in addrow function just after creating object ..
i'm new to ajax and dom
so please tell me how do do this
i have a static row where the same m_cde select box is there where this function is working prooerly
but when i do it for dynamic rows if i alert then it shows [object]
and with static rows it shows the allthe object created with id and all
also how do i pass the m_cde as arry to the url inthe showmcode function for rows .
thanks
Comment