I need to get the base url of the project in a javascript function. my code is
function add_more()
{
var numrows=parseInt(document.frm_add_announcement.cnnumrows.value)+1;
var strinner="";
var ni = document.getElementById('content');
var newdiv = document.createElement('div');
var divIdName = 'my'+numrows+'Div1';
newdiv.setAttribute('id',divIdName);
document.frm_add_announcement.cnnumrows.value=numrows;
//alert("asdAS");
strinner="<div class='row'> <div class='col-md-3'><div class='form-group'><input type='text' id='imgcaption"+numrows+"' name='imgcaption"+numrows+"' placeholder='Attachment caption' class='form-control'/></div> </div><div class='col-md-2'><div class='form-group'><input type='file' id='document"+numrows+"' name='document"+numrows+"' onclick='disableurl("+numrows+")' /></div></div><div class='col-md-1'><label for=''></label><br> <img src='../../../images/close3.png' title='Click to remove File' id='clear_multiple"+numrows+"' height='25px' style='cursor:pointer' onclick='remove("+numrows+")'/></div><div class='col-md-3'><div class='form-group'><input type='text' id='url"+numrows+"' name='url"+numrows+"' placeholder='Attachment URL' onkeyup='disablefile("+numrows+")' class='form-control'/></div></div><div class='col-md-3'><div class='form-group'><select class='form-control' id='target_type"+numrows+"' name='target_type"+numrows+"' ><option>-Choose-</option><option>Same tab</option><option>New tab</option></select></div></div></div>";
//$(".remove-btn").live('click',function() {
//$(this).parent().remove();
//});
newdiv.innerHTML=strinner;
ni.appendChild(newdiv);
}
need to get the baseurl in the src="" of the image in strinner.
var path=<?php echo base_url('') ?>. If its a js file then you need to add the above line in php while were the js file included. Now the js file can access the js variable.