Results 1 to 3 of 3

Thread: Echo Javascript string arguments (attributes construct error)

  1. #1
    Join Date
    Apr 2010

    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
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    <html xmlns="http://www.w3.org/1999/xhtml">
    <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');
    <style type="text/css">
    	text-decoration: underline;
    	color: blue;
    echo "<span onclick='CreateAssct('arg1', 'arg2);' style='cursor: pointer;'><a class='NullLink'>Create Associate</a></span>";

  2. #2
    Join Date
    Apr 2010


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

    echo "<span onclick=\"CreateAssct('arg1', 'arg2');\" style=\"cursor: pointer;\"><a class=\"NullLink\">Create Associate</span>";

  3. #3
    Join Date
    Aug 2007
    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