Solved

Problem showing javascript Calendar control using innerHTML property of div tag

Posted on 2009-07-01
6
586 Views
Last Modified: 2012-05-07
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.asp, line 82
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>

Open in new window

0
Comment
Question by:anas_elkhani
  • 5
6 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24761124
change
 var sScript="<SCRIPT DEFER>";

to
 var sScript="<SCR"+"IPT>";

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24761127
However that is not going to help
Placing a script in innerHTML will not EXECUTE the script
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24761140
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



<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>

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 24761174
ACTUALLY we can do it easier:


<div id="datearea" style="display:none">
<script language="text/javascript">
DateInput('txtFromDate',true,'DD-MON-YYYY');
</script>
</div>

and have




<script language="javascript">

function getIndex() {

  var x = document.getElementById("mySelect");

  document.getElementById("datearea").style.display=(x.options[x.selectedIndex].value==3)?'block':'none';

}

</script>

Open in new window

0
 

Author Comment

by:anas_elkhani
ID: 24763399
I used without script tag, but that takes me to another page without anything else except the date control.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24764524
Please show exactly what you did
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
problem with a simple switch code on java script 7 253
Dropdown list 4 191
Kendo Dropdown list 3 140
Update Div from child window to parent window. 4 19
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
An analysis of the phishing scam that has been affecting Google users, along with steps to take for protection, as well as what to do if you receive one of the emails.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now