Solved

Javascript Error in Onclose Handler

Posted on 2008-06-12
3
658 Views
Last Modified: 2013-11-19
I got this script of Dynamic Drive and have been trying to customise the script.

This is the original


<script type="text/javascript">

var agreewin=dhtmlmodal.open("agreebox", "iframe", "surveyinfo.asp", "UBA Survey", "width=590px,height=250px,center=1,resize=1,scrolling=0", "recal")

agreewin.onclose=function(){ //Define custom code to run when window is closed
      var theform=this.contentDoc.getElementById("eula") //Access form with id="eula" inside iframe
      var yesbox=theform.eulabox[0] //Access the first radio button within form
      var nobox=theform.eulabox[1] //Access the second radio button within form
      if (yesbox.checked==true)
            alert("You are now being redirected to our online survey\nThank you for taking time out to do this survey")
            
            else if (nobox.checked==true)
            //alert("You didn't agree to the terms")
            return true //Allow closing of window in both cases            
}
</script>

And this is the line that I have added "window.location.href="./polls/default.asp""

I want this to riderect and open a new windows but the script generates an error message before redirecting and it redirects to the parent window.

<script type="text/javascript">

var agreewin=dhtmlmodal.open("agreebox", "iframe", "surveyinfo.asp", "UBA Survey", "width=590px,height=250px,center=1,resize=1,scrolling=0", "recal")

agreewin.onclose=function(){ //Define custom code to run when window is closed
      var theform=this.contentDoc.getElementById("eula") //Access form with id="eula" inside iframe
      var yesbox=theform.eulabox[0] //Access the first radio button within form
      var nobox=theform.eulabox[1] //Access the second radio button within form
      if (yesbox.checked==true)
            alert("You are now being redirected to our online survey\nThank you for taking time out to do this survey")
            
            else if (nobox.checked==true)
            //alert("You didn't agree to the terms")
            return true //Allow closing of window in both cases
      window.location.href="./polls/default.asp"
            
}

</script>

Could someone help me out here ?
0
Comment
Question by:souldj
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
neeraj523 earned 500 total points
ID: 21768583
should be like this

this should open default.asp page in a new window before redirecting..
<script type="text/javascript">
	var agreewin=dhtmlmodal.open("agreebox", "iframe", "surveyinfo.asp", "UBA Survey", "width=590px,height=250px,center=1,resize=1,scrolling=0", "recal")
	agreewin.onclose=function(){ //Define custom code to run when window is closed
    var theform=this.contentDoc.getElementById("eula") //Access form with id="eula" inside iframe
    var yesbox=theform.eulabox[0] //Access the first radio button within form
    var nobox=theform.eulabox[1] //Access the second radio button within form
    if (yesbox.checked==true)
	{
		alert("You are now being redirected to our online survey\nThank you for taking time out to do this survey")
		window.open('./polls/default.asp','pop')
	}
    //alert("You didn't agree to the terms")
    return true //Allow closing of window in both cases
	}
</script>

Open in new window

0
 
LVL 1

Author Comment

by:souldj
ID: 21770905
Could you also add a cookie so that on the default page, the script does not load again.
0
 
LVL 22

Expert Comment

by:neeraj523
ID: 21771358
yes... u can do that..
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

830 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