Anyone got a way of thinking about this?
I'm going a bit bats working on this:
$toReturn .= "
function addProd(pExists)
{
document.getElementById('products').innerHTML = \"<tr><td id='prod_n'><input type='text' size='10' maxlength='10' name='proj_n' id='prod_n' onchange=".chr(92).chr(34)."saveData(setSaveParams('ajaxSaveDataController.php', 'PROD', 'n'), this.value)".chr(92).chr(34)." value='";
$toReturn .="'></td>
<td id='prod_spec'> <textarea cols='60' name='prod_spec' id='prod_spec' rows='20' onchange=".chr(92).chr(34)."saveData(setSaveParams('ajaxSaveDataController.php', 'PROD', 'prod_spec'), this.value)".chr(92).chr(34)." value='";
$toReturn .="'></td></tr>\" + document.getElementById('prodsTab').innerHTML;
if (pExists == 0)
{
document.getElementById('prodsTab').innerHTML = \"<tr><th id='proj_spec_h'>Name</td><th id='proj_spec_h'>Spec</td></tr>\" + document.getElementById('prodsTab').innerHTML;";
I've transcribed that so don't worry overmuch about an off topic typo.
What's going on here is I'm using PHP to write Javascript that calls an Ajax function, and what's blowing me away is the "
s and the '
s
So I'm writing a return string, in PHP, so all that's in "
Then I want to write some innerHTML, so that I can put inside \"
Then the HTML arguments can be in '
All's fine so far.
So then my onchange call is supposed to end up as onchange="function('a', 'b')"
, well, where are my "
s going to come from? If I use "
that'll end the PHP string. If I use \"
that'll end the innerHTML string. So I ended up getting PHP to interpret this chr(92).chr(34)
So that's very messy and it's starting to hurt my head.
And now it's failing on that blank line after the second $toReturn
, which I wanted there for readability.
I must be doing something wrong in terms of style or, something.
How do you handle nested "
s?