Soldato
- Joined
- 26 Aug 2012
- Posts
- 4,449
- Location
- North West
Hi, I have a foreach loop, roughly as shown below, excluding the unimportant stuff.
I am trying to pass to PHP variables based on the progress within the foreach loop, to a JavaScript function. The variables get passed right to the HTML feed,just not the JS function. The variables I need to pass to the js function are $feed->name and $feed->URL.
I read up elsewhere that the best way to pass these to the JS function as parameters is to set them as JS variables first and then use these as parameters to the function.
So in this case I need to set
However, I just can't get this to work within the heredoc, no matter what I've tried which i've found online, as obviously it gets processed as the literal value rather than a variable. I am not very knowledgeable in JS, just to let you know.
Any help would be more appreciated.
I am trying to pass to PHP variables based on the progress within the foreach loop, to a JavaScript function. The variables get passed right to the HTML feed,just not the JS function. The variables I need to pass to the js function are $feed->name and $feed->URL.
I read up elsewhere that the best way to pass these to the JS function as parameters is to set them as JS variables first and then use these as parameters to the function.
So in this case I need to set
Code:
<script>
var feedName=<?php echo $feed->name ;?>
var feedUrl= <?php echo $feed->url ;?>
</script>
However, I just can't get this to work within the heredoc, no matter what I've tried which i've found online, as obviously it gets processed as the literal value rather than a variable. I am not very knowledgeable in JS, just to let you know.
Any help would be more appreciated.
PHP:
foreach($rss_feeds as $feed)
{
echo <<< HTML
<tr>
<td><form action="router.php" method="post">
<input name="edit-feed" type="hidden" value="$feed->id" />
<input name="edit-feed-submit" type="submit" value="Edit" class="edit-feed-button" onclick="javascript:modify_feed(feedName,feedUrl);" /></form>
</td>
</tr>
HTML;
}
Last edited: