-7

can you help me i have problem insert variable php into jquery, this my script:

<script type="text/javascript">
$("#add").click(function() {
    var error = <?php echo $reportErr; ?>;
    $("#table").append("<tr><td> <input type='text' name='report[]' /> <a href='javascript:void(0);' class='rem'>-</a>"+error+"</td></tr>");
});
$("#table").on('click','.rem',function() {
    $(this).parent().parent().remove();
});

<?php 
$report = "error";
$reportErr = $report;
?>
1
  • 1
    Look at the JavaScript you are generating. Is it what you expect? Look at your JavaScript console? Are there any errors? Frankly - do some debugging yourself. Commented Sep 29, 2014 at 17:59

1 Answer 1

4

At first glance, you have a syntax error. Your string needs to be in quotes.

Try var error = "<?php echo $reportErr; ?>";

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.