SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error checking & JS

    ok, i'm not sure if this should have went in the cs-s forum, but it involves php, so i put it here.

    i'm getting an "Unterminated String Constant" error on line 4 of my error script.
    heres the whole script:
    PHP Code:
    <?php
    function error($msg)
    {
    ?>
    <html>
    <head>
    <script language="JavaScript1.1">
    <!--
    alert("<?php echo $msg?>");
    history.back();
    // End -->
    </script>
    </head>
    <body>
    </body>
    </html>
    <?
    exit;
    }
    ?>
    and here's the html code. the error is coming up on line 4:
    Code:
    <html>
    <head>
    <script language="JavaScript1.1">
    <!--
    alert("One or more required fields was left blank.
    Please fill them in and try again.");
    history.back();
    // End -->
    </script>
    </head>
    <body>
    </body>
    </html>
    I've checked the JS against another example i got in the forums search which involved disallowing right clicking. looked fine. anyone know why that error is coming up?
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    alert("One or more required fields was left blank. 
    Please fill them in and try again.");
    Without knowing much js, my guess is that the error is caused because you have broken the the string over two lines. Perhaps js doesn't like line breaks within statements; ie a statement must be on the one line. This is just a guess.

    Try
    Code:
    alert("One or more required fields was left blank. Please fill them in and try again.");
    But then, I don't know if JavaScript interprets the newlin charactger \n either.
    Last edited by freakysid; Aug 3, 2001 at 03:13.

  3. #3
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    funny you mention that:
    PHP Code:
    error("One or more required fields was left blank.\nPlease fill them in and try again."); 
    thats what error is sending
    even
    PHP Code:
    error("One or more required fields was left blank."); 
    doesn't work
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this a javascript error or a php error being generated?

  5. #5
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    /me feels dumb.
    when i tried it w/o the \n, i hadn't uploaded the script again.
    the \n caused the error. works fine with it as 1 line.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •