Is there anyway to use PHP within javascript. For example I want to do: var textarea = '<div id="'+obj.id+'_editor"><textarea id="'+obj.id+'_edit" name="'+obj.id+'" rows="4" cols="60">'+obj.innerHTML+'</textarea><input type="hidden" name="'+obj.id+'_resultid" value="<? echo $id ?>">'; var button = '<div><input id="'+obj.id+'_save" type="button" value="Save edit" /> or <input id="'+obj.id+'_cancel" type="button" value="Cancel edit" /></div></div>'; HTML: And have php echo something in the value (echo) bit. How would I go around doing this? Thanks alot!
it's possible, if you have the javascript inside the html the php will be processed inside it, for example <? $phptext = 'Hello World\n'; ?> <script language="javascript"> var text = '<?=$phptext ?>'; document.write(text); </script> HTML: Couple of things to note, make sure you wrap the php vars in single quotes, else newlines will be literal and break the javascript, also the php is only processed once as the page loads, not everytime something changes ....