Hello,
I've spent a lot of time to make a function that adds text inputs to a form with the use of innerHTML but I have just found out that those dynamic text fields are totally absent from the POST request!
The created input have all the same name, like this :
... name="dyna_field[0]" ...
... name="dyna_field[1]" ...
... name="dyna_field[2]" ...
Here is the Javascript code anyway :
Any help would be greatly appreciated !
I've spent a lot of time to make a function that adds text inputs to a form with the use of innerHTML but I have just found out that those dynamic text fields are totally absent from the POST request!
The created input have all the same name, like this :
... name="dyna_field[0]" ...
... name="dyna_field[1]" ...
... name="dyna_field[2]" ...
Here is the Javascript code anyway :
Code:
// template of the fields to be added dynamically
var cats_html_temp = new Array();
cats_html_temp[0] = '┕━━';
cats_html_temp[1] = ' ';
cats_html_temp[1] += '<input type=\"hidden\" name=\"form_ecom_cat_ID[{row_num}]\" value=\"\">';
cats_html_temp[1] += '<input type=\"hidden\" name=\"form_ecom_cat_parent_ID[{row_num}]\" value=\"{cat_parent_ID}\">';
cats_html_temp[1] += '<input type=\"text\" name=\"form_ecom_cat_name[{row_num}]\" value=\"{cat_parent_ID}\" class=\"field1\" maxlength=\"55\" style=\"background: #fd2f16; color: #ffffff\">';
cats_html_temp[1] += ' <input type=\"checkbox\" name=\"form_ecom_cat_status[{row_num}]\" value=\"show\" onclick=\"defocus(this)\">';
cats_html_temp[1] += '<a href=\"javascript:';
cats_html_temp[1] += 'elem_div_add( \'before\' , {row_num} , {cat_parent_ID} , {pixel_num} , cats_html_temp );';
cats_html_temp[1] += 'defocus(this);';
cats_html_temp[1] += '\" class=\"warnlinknorm\"> [ + ↑ ] </a>';
cats_html_temp[1] += '<a href=\"javascript:';
cats_html_temp[1] += 'elem_div_add( \'after\' , {row_num} , {cat_parent_ID} , {pixel_num} , cats_html_temp );';
cats_html_temp[1] += 'defocus(this);';
cats_html_temp[1] += '\" class=\"warnlinknorm\"> [ + ↓ ] </a>';
cats_html_temp[1] += ' . ';
cats_html_temp[1] += '<a href=\"javascript:';
cats_html_temp[1] += 'elem_div_del( {row_num} );';
cats_html_temp[1] += '\" class=\"warnlinknorm\"> [ - ] </a>';
Code:
// function that creates the fields
function elem_div_add ( method , parent_num , cat_parent_ID , pixel_num ) {
parent_id = 'row_' + parent_num;
if ( !row_num ) var row_num = document.getElementById( 'root' ).getElementsByTagName( 'div' ).length;
if ( method == 'before' ) var next_elem = document.getElementById( parent_id );
if ( method == 'after' ) var next_elem = document.getElementById( parent_id ).nextSibling;
row_num++;
if ( pixel_num > 0 ) {
var prefix = cats_html_temp[0];
} else {
var prefix = '';
}
var cell_content_new = '';
cell_content_new = prefix + cats_html_temp[1];
cell_content_new = cell_content_new.replace( /{cat_parent_ID}/g , cat_parent_ID );
cell_content_new = cell_content_new.replace( /{row_num}/g , row_num );
cell_content_new = cell_content_new.replace( /{pixel_num}/g , pixel_num );
cell_content_new = cell_content_new.replace( /{parent_id}/g , parent_id );
var div = document.createElement( 'div' );
div.setAttribute( 'id' , 'row_' + row_num );
if ( method == 'inside' ) {
var parent_node = document.getElementById( parent_id );
parent_node.appendChild( div );
} else {
var parent_node = document.getElementById( parent_id ).parentNode;
parent_node.insertBefore( div , next_elem );
}
document.getElementById( 'row_' + row_num ).style.padding = '0px 0px 0px ' + pixel_num + 'px';
document.getElementById( 'row_' + row_num ).innerHTML = cell_content_new;
}
Code:
// the ways the function is called
<a href="javascript:
elem_div_add ( 'before' , 0 , null , 0 );
defocus(this);
" class="warnlinknorm"> [ + ↑ ] </a>
<a href="javascript:
elem_div_add( 'after' , 0 , null , 0 );
defocus(this);
" class="warnlinknorm"> [ + ↓ ] </a>
<a href="javascript:
elem_div_add( 'inside' , 0 , 1 , 40 );
defocus(this);
" class="warnlinknorm"> [ + → ] </a>
Any help would be greatly appreciated !