Solved

Problem showing javascript Calendar control using innerHTML property of div tag

Posted on 2009-07-01
6
577 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In this step by step tutorial with screenshots, we will show you HOW TO: Enable SSH Remote Access on a VMware vSphere Hypervisor 6.5 (ESXi 6.5). This is important if you need to enable SSH remote access for additional troubleshooting of the ESXi hos…
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 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

20 Experts available now in Live!

Get 1:1 Help Now