Anas El-Khani
asked on
Problem showing javascript Calendar control using innerHTML property of div tag
I am getting error message while calling a javascript function on dropdown onchange event. The javascript function I called getIndex() is supposed to show jason's calendar control that in turn uses <script> tag using innerHTML property of <div> where I want to show this calendar control with some other HTML tags like <table>. I have tried <script defer> but that didn't helped.
The following error comes while loading this page:
Active Server Pages error 'ASP 0138'
Nested Script Block
/progress/request_search.a sp, line 82
A script block cannot be placed inside another script block
The following error comes while loading this page:
Active Server Pages error 'ASP 0138'
Nested Script Block
/progress/request_search.a
A script block cannot be placed inside another script block
<script language="javascript">
function getIndex()
{
var x=document.getElementById("mySelect");
var i=x.selectedIndex;
var selval=document.getElementById("frmcreaterequest").mySelect.options[i].value;
if (selval==3)
{
var sScript="<SCRIPT DEFER>";
sScript = sScript + "DateInput('txtFromDate',true,'DD-MON-YYYY')";
sScript = sScript + "</SCRIPT" + ">";
document.getElementById("datearea").innerHTML=sScript;
document.getElementById("datearea").style.display='block';
}
else if (selval==4)
{
document.getElementById("datearea").style.display='none';
}
else if (selval==1)
{
document.getElementById("datearea").style.display='none';
}
else if (selval==2)
{
document.getElementById("datearea").style.display='none';
}
}
</script>
However that is not going to help
Placing a script in innerHTML will not EXECUTE the script
Placing a script in innerHTML will not EXECUTE the script
What you are trying to do will not work since the script does a document.write.
Instead we change the document.write of the function to return a string and do
Instead we change the document.write of the function to return a string and do
<script language="javascript">
var myString = ""
function getIndex() {
var x=document.getElementById("mySelect");
var selval=x.options[x.selectedIndex].value;
document.getElementById("datearea").style.display='none';
if (selval!=3) return; // no need to continue
var myWrite = document.writeln;
myString = ""
document.writeln = function(str) {
myString += str+'\n';
}
DateInput('txtFromDate',true,'DD-MON-YYYY');
document.writeln=myWrite;
document.getElementById("datearea").innerHTML=myString;
document.getElementById("datearea").style.display='block';
}
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I used without script tag, but that takes me to another page without anything else except the date control.
Please show exactly what you did
var sScript="<SCRIPT DEFER>";
to
var sScript="<SCR"+"IPT>";