I have an integer that is being added dynamically into a form, the initial form is loaded with template variables.
The section I want to convert is a the template_parent, I am aware the .replace is responsible for returning the string but is it possible to convert this to an integer and have it retained within the innerHTML?
var number = parseInt(pVal);
var ts = 't' + new Date().getTime();
var template=document.getElementById('akSelectValueWrapTemplate');
var newRowEl=document.createElement('div');
newRowEl.innerHTML=template.innerHTML.replace(/template_clean/ig,ts).replace(/template_parent/ig,number).replace(/template/ig,val);
newRowEl.id="akSelectValueWrap_"+ts;
newRowEl.className='akSelectValueWrap';
$('#attributeValuesWrap').append(newRowEl);
I thought I might be able to use php and intval() with the value, however when turned into an integer, it becomes 0
My php section starts,
if ($v == 'TEMPLATE') {
$akSelectParentValue = 'TEMPLATE_PARENT';
$akSelectValueID = 'TEMPLATE_CLEAN';
$akSelectValue = 'TEMPLATE';
} else {
if ($v->getSelectAttributeOptionTemporaryID() != false) {
$akSelectValueID = $v->getSelectAttributeOptionTemporaryID();
} else {
$akSelectValueID = $v->getSelectAttributeOptionID();
}
$akSelectParentValue = $v->getSelectAttributeOptionParentValue();
$akSelectValue = $v->getSelectAttributeOptionValue();
}
if($akSelectParentValue>0){
//do stuff
}else{
//come back as string when new,
//var_dump($akSelectParentValue)
//string(15) "135"
}
Edit: I have just realised that the string(15) is the string length of the original value not the Parent ID, can I delay this function of pass through the amended variable once the replacement has been done?.
Edit2: I am doing this within concrete 5 and have created a new attribute, that allows the choice of a parent category for each option added.
I believe I need to use Ajax here to post the html at a later date the string(15) indicates that the variable when processed is not an integer, but instead the string "TEMPLATE_PARENT"
I have not fixed it yet, however now I know where I am going wrong it should be a little easier to continue.