tags:

views:

45

answers:

3

Hello,

I have a table that is passed via ajax and displayed. When the code is passed, it also passed all the javascript associated with the pass, as the code doesn't seem to work if I just put it in the page that it is being passed to.

When I click a in the table that has been passed, I would like to take the data convert it to a input field. Each TD has a class of table2, so in theory this should be simple.

$(".table2").click(
    function () {
        var html = $(this).html();
        $(this).empty().html('<input name="" type="text" value="' + html + ' " />);
    });

But I get a

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /products.php on line 90

When I try to do an ajax call on it.

If I try creating php variables, and passing the form data that way, I get an illegal XML error.

Any ideas?

EDIT

The reason I didn't include the PHP is that it is rather lengthy, and all it is doing is echoing some HTML/JS:

$dbh=mysql_connect ("name","user", "pass") or die('I cannot connect to the database because:'. mysql_error());

        echo '<script type="text/javascript" charset="utf-8">
        $(".table2").click(
        function () {
            var html = $(this).html();
            $(this).empty().html('<input name="" type="text" value="' + html + ' " />');
        }); 


    });


    </script>

    <table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="table2">data</td>
    <td class="table2">data</td>
  </tr>
   <tr>
    <td class="table2">data</td>
    <td class="table2">data</td>
  </tr>
</table>
        ';

And it works fine is I replace

$(this).empty().html('<input name="" type="text" value="' + html + ' " />');

With something like alert("you click me!");

A: 

I received the same error message when I pasted that line to my IDE, Eclipse PHP Development Tools. I removed a few unnecessary quotes and it took away the red underlines and here is the function.

$(this).empty().html("<input name="" type="text" value="' + html + ' " />");
Anthony Forloney
Line 90 is the empty().html() line.I plugged in the code you gave and now it returns: `missing ) after argument list $(this).empty().html("<input name="" type="text" value=" " />");`
Jared
Your code seems to be looking for a php $html value that doesn't exist?
Jared
Er that was my fault, I just added the `$` and PHP's `.` concatenation operator to make it do something, my bad. It was late at night :(
Anthony Forloney
For whatever reason, all I had to do was link to a Javascript with the code in it and it worked. If I include it locally, it won't work. Strange.
Jared
A: 
    $(this).empty().html('<input name="" type="text" value="' + html + ' " />);

you dont have '

try this

    $(this).empty().html('<input name="" type="text" value="' + html + ' " />');
thanks for pointing that out... that was actually a side issue that I fixed, but didn't resolve this problem.
Jared
A: 

Use an php ide to avoid this kind of sintax errors and detect it instantainly

useless