/    Sign up×
Community /Pin to ProfileBookmark

Passing php var from loop to js.

Hello,

I’m trying to pass a $counter2 value from php loop to javascript, but $counter2 is incremented so I’m passing the highest value of $counter2, which i not what I want to do. Is there a way to somehow combine values with html identifiers and pass them to js?I would be grateful for assistance.

Link to code:
[url]http://studentuczy.ayz.pl/Calendar/calendar.txt[/url]
What is it?
[url]http://studentuczy.ayz.pl/Calendar/calendar.php[/url]

Thank you in advance.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991May 03.2010 — PHP and JavaScript operate at different times. If you load the page, and view the source, you'll see that you define thatday a few different times (at least if I've counted brackets properly), and the last value is the one that will be taken. If you want them all, you'll need an array.

I have no idea what you are talking about combining with html identifiers. Perhaps you could explain in a bit more detail what you want to happen?
Copy linkTweet thisAlerts:
@mstatwebdevauthorMay 03.2010 — Thanks for your reply.

sure, i know that php is server side and js is client side.

I want to get the php $counter2 value, which is the date value for my calendar, and pass it to js script, right there:

document.observe('dom:loaded', function() {

$$('#show').each(function(element) {

new Tip(element, {

ajax: {

url: 'test.html',

options: {

onComplete: function() { alert('ajax content loaded'); alert(thatday); }

}

}

});

});

});

The problem is, js is client side, so if i assign to var thatday in js $counter2 value, in the end it will have highest $counter2 value. I want to get it working dynamically, to pass value for each cell (every $counter2 value to js), so when i run the js function for cell where $counter2 equals 3, I want that 3 to be passed, not max $counter2 value, which for this month, May, is 31.

One more time, thanks.
Copy linkTweet thisAlerts:
@mstatwebdevauthorMay 03.2010 — as for the hmtl ids: mb ids should be counted in js to get the proper $counter2 value.
×

Success!

Help @mstatwebdev spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...