below is a part of my javascript file
$("#imgBox").append('<div id="inner_div_electric" style="position: relative; top: '+innerDivElectricTop+'px; left: '+innerDivElectricLeft+'px;width:'+innerDivElectricWidth+'px;height:'+innerDivElectricHeight+'px;"></div>');
for(var i=1; i<=sidewalls; i++)
{
for(var j=1; j<=backwalls; j++)
{
var newDiv = "<span id='droppable"+i+""+j+"' onclick='changeText(this.id);' class='droppable_class' style='width:"+(cellWidth-2)+"px; height:"+(cellHeight-2)+"px;border:1px dotted red;display:inline-block;margin:0px;padding:0px;float:left;'></span>";
$("#inner_div_electric").append(newDiv);
}
}
Here imgBox is a div, and in that div am dynamically creating spans to generate sqare boxes in that div.
$('.droppable_class').html('');
if($('#'+id).html(''))
{
$('#'+id).html('<font face="calibri" color="red"><b>OUTLET</b></font>');
}
This is the code to generate the text 'OUTLET' in a span which I clicked. I need to send the div as it is from this javascript file to php to generate pdf of that particular diagram which contains sqare boxes and one particular span contains the text 'OUTLET'.
Any ideas how to achieve it?
Thanks
This one is easy, just dynamically inputs, and add them to a form; then, you can manually call submit on the form with $('#formid').submit();
Also, with Javascript you can override .submit() if you wanted. Think about this:
<span>
<form id="sform">
<input name="someDynamicallyCreatedInput" /> <!-- use this instead of a div (or just copy your div to here)-->
</form>
<script>
$('#sform').submit(function(e){//function to be called before form is sent
//if you want to manually send it, wihtout using default form behavior... just put this:
//e.preventDefault();
//then do some ajax here, or heck, just let the form send the data if you are changing pages.
//however, if you want to download a pdf, you may want to just send a get request using href...
});
</script>
</span>
Exporting as a pdf is simply a matter of setting the Content-Type using the php header() function.
Sources: http://api.jquery.com/submit/ http://php.net/manual/en/function.header.php //there is a great example here for pdfs.