www.webdeveloper.com
Results 1 to 3 of 3

Thread: Echo Javascript string arguments (attributes construct error)

  1. #1
    Join Date
    Apr 2010
    Posts
    20

    Echo Javascript string arguments (attributes construct error)

    Why does the the following javascript function not work? This is not valid HTML (that is the problem). This works when not passing any arguments to the function. I think I'm required to have all element attribute values in quotes for XHTML standards. I've tried placing my echo statement argument in double and single quotes, and they both do not work. What simple thing am I missing?

    I get an
    attribute value literal can occur in an attribute specification list only after a VI delimiter
    and an
    attributes construct error
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" />
    <script type="text/javascript" language="javascript">
    function CreateAssct(arg1,arg2){
    	alert('im here');
    }
    </script>
    <style type="text/css">
    a.NullLink{
    	text-decoration: underline;
    	color: blue;
    }
    </style>
    </head>
    <body>
    <?php
    echo "<span onclick='CreateAssct('arg1', 'arg2);' style='cursor: pointer;'><a class='NullLink'>Create Associate</a></span>";
    ?>
    </body>
    </html>

  2. #2
    Join Date
    Apr 2010
    Posts
    20

    Solved

    You need to escape your double quote characters. The following code works:

    Code:
    echo "<span onclick=\"CreateAssct('arg1', 'arg2');\" style=\"cursor: pointer;\"><a class=\"NullLink\">Create Associate</span>";
    http://stackoverflow.com/questions/1...ments-from-php

  3. #3
    Join Date
    Aug 2007
    Posts
    3,767
    View the page source and you will see why. Not the PHP file, but the code sent to the browser. Always remember that's what JavaScript operates on.
    Great wit and madness are near allied, and fine a line their bounds divide.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles