0

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

3 Answers 3

1

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.

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

Comments

0

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).

2 Comments

It worked. var arrayFromPHP = <?php echo json_encode($arrSGoal); ?>; $.each(arrayFromPHP, function (i, elem) { alert(elem);alert(i); });
I worked around the jscon_encoded array. how i can get the modified array back to php
0

You can echo php variables in jquery/javascript, something like this:

alert('Your score is <?php echo "$variable" ?> . Thank you for playing.');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.