[Javascript] innerHTML problem

pedro mpa mail.pmpa at sapo.pt
Mon Oct 9 16:18:00 CDT 2006


Hi.
Thanks for replying.

I tried using   but no success.
You can also use empty comment <!----> I think.

Pedro.


-----Mensagem original-----
De: Cutter (JSRelated)
 
In my experience, the element must contain something before you are able 
to replace it's contents with innerHTML. This may not be true for all 
browsers, but I have found that if I have at least a non-breaking space 
(&nbsp;) in the contents of the div to begin with then I generally never 
have an issue in any browser on any platform. Anyone else seen similar?

Cutter

pedro mpa wrote:
> Hi!
> 
> I'm trying to change the innerHTML of a div for a date time picker using
> javascript.
> 
> [...]
> <div id="datetimepicker"></div>
> 
> <script id="dyn_js_element" src="" language="javascript"
> type="text/javascript"></script>
> 
> <script language="javascript" type="text/javascript">
> function DynamicScriptSrc(script_src_url) {
> 	document.getElementById("dyn_js_element").src=script_src_url;
> 	//(1) alert();
> }
> 
> // first call:
> DynamicScriptSrc('datetimepicker.61009.php');
> </script>
> [...]
> 
> // The php script returns js code for dyn_js_element (exmaple):
> document.getElementById('datetimepicker').innerHTML =
> '<?=str_replace("\t","", str_replace("\r\n","",$content))?>';
> 
> The problem is the innerHTML of the div datetimepicker only gets updated
if
> I add an alert(); (1) to the DynamicScriptSrc function, although it works
on
> the first call. Why? Is there a workaround? :)
> 
> Does an innerHTML cross-browser function/property exists?
> 
> Apologies for my bad English.
> 
> Thanks in advance.
> Pedro.






More information about the Javascript mailing list