No announcement yet.

Problem with embedding JS code in PHP

  • 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):

         $submission_form ="
            <p style=\"font-size:20px; padding: 15px;\">
                <u>Please select the type of analysis you wish to perform</u>
            <form name=\"analysis_form\" method=\"post\">  
                <a id=\"myHeader1-2\" href=\"javascript:showonlyonev2(\"newboxes1-2\");\" >
                    <input type=radio name=\"criterion\" value=\"single_genotype\">
                    Single-study analysis using genotypes
    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.


    • #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

      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, 09:51 PM.