Web Analytics Made Easy -
StatCounter One event handler, many actions - Works In IE but not in Netscape - CodingForum

Announcement

Collapse
No announcement yet.

One event handler, many actions - Works In IE but not in Netscape

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • One event handler, many actions - Works In IE but not in Netscape

    Hi everyone,

    I am new to programming and indeed javascript, though I have managed to pick up a few skills from a number of tutorials including tips from this Forum. Thanks to all.

    However, I have come up against something that i must confess has drawn me to the battlefront. Half won, half lost.

    Here's my dilema.


    I am trying to write a code to help me achieve the following results.

    1. I have one checkbox on a page which I want the user to check before they submit the page.

    2. I would like the checkbox to be validated so that, the user will have to check it before they can proceed. If they do not, they will be reminded to do so, unless they chose to exit the page via an exit button.

    3. On validating and successfully submitting the form, I would like a popup window to open and close itself whilst redirecting the parent window to a hidden redirect value in the popup.


    Sounds complicated or confusing?

    Well, I got it working in IE, but netscape is refusing to do both (ie; validate and open the popup window) It will do one or the other.

    OK here's the breakdown and code

    On the page with the checkbox, I've got:

    -----------------------------------------------------------
    In the head of the Main Page,
    -----------------------------------------------------------

    #<script language="Javascript">
    #<!--
    #function validateForm() {
    #var check_box = document.terms.check_box.checked;
    #if (check_box == false) {
    #alert("Please agree before continuing");
    #return false;
    #} else {
    #return true;
    #}
    #}
    #// -->
    #</script>

    #<script>
    #var theURL = 'popuppage.html';
    #var width = 200;
    #var height = 100;
    #function popRedirect() {
    #newWindow = window.open(theURL,'newWindow','toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,location= no,width='+width+',height='+height);
    #}
    #</script>

    ------------------------------------------------------------
    In the body of the popup window,
    ------------------------------------------------------------

    <body>

    #<form action="javascriptopRedirect()" onSubmit="return validateForm()" method="get" name="terms" >
    Please check this box to Accept : <input type="checkbox" name="check_box" value="terms">

    <p>
    #<input type="image" src="../../images/iagree2.gif" onSubmit="return validateForm(); popRedirect()" border="0" onMouseOver="window.status='Accept'; return true;" onMouseOut="return true;">


    -----------------------------------------------------------
    In the head of the PopUpPage,
    -----------------------------------------------------------

    <head>

    #<script>

    #var browser_type=navigator.appName
    #var browser_version=parseInt(navigator.appVersion)

    #//if NS 4+
    #if (browser_type=="Netscape"&&browser_version>=4)
    #window.location.replace("redirect_to_page.html")
    #//if IE 4+&&browser_version>=4)
    #window.location.replace("redirect_to_page.html")
    #else if (browser_type=="Microsoft Internet Explorer
    #//Default goto page (NOT NS 4+ and NOT IE 4+)
    #else
    #window.location="redirect_to_page.html"
    #</script>

    #<script>
    #var Timer = 10000;
    #t = null;
    #function closeMe(){
    #t = setTimeout("self.close()",Timer);
    #}
    #</script>

    ------------------------------------------------------------
    In the body of the popup window,
    ------------------------------------------------------------

    #<body onload="javascript:load('redirect_to_page.html',top.opener,top.close())"


    ---------------------------------------

    If the above does not display properly, please see the attached txt. file.

    Thanks to all who take the time to read and help.

    Regrads
    Invincible
    Attached Files

  • #2
    I'm not sure where you want your checkbox. But here's a crack at it...


    Main page:
    <HTML>
    <HEAD>
    <script language="Javascript">
    <!--
    function validateForm() {
    var cbchecked = document.terms.check_box.checked;
    if (cbchecked == false) {
    alert("Please agree before continuing");
    } else {
    popRedirect();
    }
    }

    var theURL = 'popuppage.html';
    var width = 200;
    var height = 100;
    function popRedirect() {
    newWindow =

    window.open(theURL,'newWindow','toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,l

    ocation=no,width='+width+',height='+height);
    }
    // -->
    </script>
    </HEAD>
    <BODY>
    <FORM NAME="terms" onSubmit="return false;">
    <INPUT TYPE="checkbox" NAME="check_box" > Agree to terms<BR>
    <INPUT TYPE="button" NAME="Continue" VALUE="Continue" onClick="validateForm()">
    </FORM>
    </BODY>
    </HTML>

    popuppage.html
    <html>
    <HEAD>
    </HEAD>
    <BODY>
    <FORM NAME="terms">
    You still agree?
    <INPUT TYPE="button" NAME="No" VALUE="No" onClick="self.close()">
    <INPUT TYPE="button" NAME="Yes" VALUE="Yes" onClick="opener.location = 'redirect_to_page.html';self.close()">
    </FORM>
    </BODY>
    </html>

    Comment

    Working...
    X