Reputation: 4957
In the below code i have an array arrSGoal. On Click of RemoveGoal i need to delete or set the value to 0 for the the id in the array. Array is in php. dont know how to use in the jquery.
<SCRIPT LANGUAGE="JavaScript">
$(document).ready(function() {
$('a.removegoal').click(function(e)
{
e.preventDefault();
//Getting the TR to remove it in case of successful deletion
var objRow = $(this).closest('tr');
objRow.remove();
});
});
$arrSGoal[$i] = $row->id_goals;
?>
<tr>
<td style='vertical-align:top;'>
<textarea name="stg<?php print $i;?>" id="short_goal" class="short_go"><?php print $row->goal_description?></textarea>
</td> < td style='vertical-align:bottom;' nowrap> <span class='hidden'> echo $i </span> <a href=# class="removegoal" >Remove Goal
Upvotes: 0
Views: 581
Reputation: 20722
Once your HTML page has been served up the PHP is "dead" - its already been executed and completed and no longer exists. Its output was your HTML page -- the PHP is gone.
In order for you to do this you'd either have to have an AJAX call to the server and provide it what the information you wish to update, or have the link submit a form with that info, and do it (again) server side.
PHP doesn't actually run in your browser.
Upvotes: 1
Reputation: 382696
You can echo php variables in jquery/javascript, something like this:
alert('Your score is <?php echo "$variable" ?> . Thank you for playing.');
Upvotes: 0
Reputation: 449435
I don't understand your code, but a good way to "export" an array from PHP into Javascript is json_encode().
At any rate, you need to be aware that PHP is executed server side, and Javascript on the client side. There is no way to directly interact between the PHP code and Javascript, e.g. to do a calculation in JQuery and have PHP work with the result. (Well, without AJAX, that is).
Upvotes: 0