/    Sign up×
Community /Pin to ProfileBookmark

javascript and php–> check variable in javascript with php variable

Dear all,

I have the php page with javascript. If I have php variable, can it be used in javascript to check the flag or I need to hardcode it in javascript as shown below of “checkServiceCategory”? Dynamic or static??

php
<?php
foreach ($result as $id=>$value) {
if([B]$value[0]->isServiceCategory[/B])
return true;
}

//——————Or ———————————-//
isEmptyUploadFile(function(r)
{
var checkServiceCategory=document.getElementById(‘category-group’).value;
if([B]checkServiceCategory!=85[/B] && (fileList == null || fileList.length == 0))
{
$(“#uploadImgError”).html(‘<em><span style=”color:red”> <i class=”icon-cancel-1 fa”></i> Please Upload at least one image!</span></em>’);
location.href = “#uploadImgError”;

return false;
}
else

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@rootMar 28.2016 — JQuery, see my signature.
Copy linkTweet thisAlerts:
@WebnerdMar 29.2016 — WTF are you talking about? PHP is server-side, Javascript is browser. Dynamic or Static? Go back to washing dishes because your skills in understanding code are really bad.
Copy linkTweet thisAlerts:
@SempervivumMar 29.2016 — This posting is not helpful. No need to be rude, when a member doesn't have much knowledge about javascript and PHP yet.

Interaction betwenn PHP and JS is a common task. E. g. assigning a PHP variable to a javascript one:
[CODE]var myvar_js = <?php echo $myvar_php; ?>[/CODE]
[CODE]var myimgs = <?php echo glob("mypath/*.jpg"); ?>[/CODE]

@AMrchiu5hk: However I do not understand you intention too. Why a PHP loop? Please explain more detailed

what you intend to do.
×

Success!

Help @rchiu5hk 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...