Announcement

Collapse
No announcement yet.

Problem with embedding JS code in PHP

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

  • Problem with embedding JS code in PHP

    Hi all,

    I have the following string as part of my PHP code (before you ask, it HAS to be in PHP, can't write PHP and HTML separately):

    Code:
         $submission_form ="
            <p style=\"font-size:20px; padding: 15px;\">
                <u>Please select the type of analysis you wish to perform</u>
            </p>
            <form name=\"analysis_form\" method=\"post\">  
            <div>
                <a id=\"myHeader1-2\" href=\"javascript:showonlyonev2(\"newboxes1-2\");\" >
                    <input type=radio name=\"criterion\" value=\"single_genotype\">
                    Single-study analysis using genotypes
                </a>
            </div>
    Everything works fine, except the JS part...Because it should have single quotes, but this I can't do it inside the PHP string...
    Any ideas?

  • #2
    Whenever I need to put quotes inside a string in PHP, I wrap the string in PHP using apostrophes ' rather than quotation marks " which then means I can use quotation marks within the string.

    Comment


    • #3
      Your javascript doesn't work because you are using the same type of quote " in your html. So the browser reads "javascript:showonlyonev2("

      It should be
      \"javascript:showonlyonev2('newboxes1-2');\"

      Also when using a large string consider creating a seperate file then echoing the contents of that file. Then you don't need \" at all.
      Last edited by fiveworlds; 04-29-2016, 10:51 PM.

      Comment

      Working...
      X