Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
JavaScript IN php... Help please!
Old 09-09-2008, 01:34 PM JavaScript IN php... Help please!
Skilled Talker

Posts: 68
Name: Avi Zolty
Location: Atlanta
Trades: 0
Okay, so I have a code scripted in Javascript which prompts a password prompt. In the "if" section, i wanted to make a php function which will then act on a "for" value. However, now in the php (which in turn is in the Javascript) I have to make another Javascript command (so I can send a "for" value).. But I do not know how I would do that.

The script would look something like this:

<html>
<head>
<script type="text/javascript">
<!--
pass=prompt("type in the password","password here");
if (pass==123)
{
<?php
MyFunction ()
{
Here is where I want to insert the Javascript command of a "for" then an alert.. like this: var 1="angel"; var 2="Josh"; var 3="John"; for (x=1,x=<3,x++) {alert ("hey," + x + "!")}
}
MyFunction;
MyFunction;
?>
}
else
{
alert("password is incorrect");
}
//-->
</script>
</head>
<body>

</body>
</html>
Zoltar1992 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-09-2008, 01:38 PM Re: JavaScript IN php... Help please!
Skilled Talker

Posts: 68
Name: Avi Zolty
Location: Atlanta
Trades: 0
P.s. I know i could make an array in Php (I think...) and then use a case instead of a for... but the "case" is still Java script, and I vaguely remember there being a php command similar to a case...
but I still want to know for future reference how to embed a language (like javaScript) into a php block, which is in the language itself.
Zoltar1992 is offline
Reply With Quote
View Public Profile
 
Old 09-09-2008, 01:44 PM Re: JavaScript IN php... Help please!
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Yeah... I think there is a bit of misunderstanding here. Anything that you execute in PHP happens BEFORE anything reaches the browser. Anything that happens in JavaScript is executed AFTER all of the information has been received from the server. The only exception to this is when making AJAX requests, which is just a way for the browser to send requests for more data, then display it without needing to refresh the window.

There is nothing wrong with using PHP to write JavaScript, but you must keep in mind that all of your PHP will be done executing by the time you get around to even beginning to execute JavaScript.

If you need the extra power of PHP to return data to your client-side script mid-execution, I recommend you study AJAX, because that is the way you need to do it.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 09-09-2008, 09:48 PM Re: JavaScript IN php... Help please!
thehuskybear's Avatar
Ultra Talker

Posts: 362
Name: Sam
Location: Tucson, AZ
Trades: 1
Quote:
Originally Posted by wayfarer07 View Post
Yeah... I think there is a bit of misunderstanding here. Anything that you execute in PHP happens BEFORE anything reaches the browser. Anything that happens in JavaScript is executed AFTER all of the information has been received from the server. The only exception to this is when making AJAX requests, which is just a way for the browser to send requests for more data, then display it without needing to refresh the window.

There is nothing wrong with using PHP to write JavaScript, but you must keep in mind that all of your PHP will be done executing by the time you get around to even beginning to execute JavaScript.

If you need the extra power of PHP to return data to your client-side script mid-execution, I recommend you study AJAX, because that is the way you need to do it.
I agree, it sounds like AJAX is what you need.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
thehuskybear is offline
Reply With Quote
View Public Profile Visit thehuskybear's homepage!
 
Old 09-09-2008, 09:49 PM Re: JavaScript IN php... Help please!
thehuskybear's Avatar
Ultra Talker

Posts: 362
Name: Sam
Location: Tucson, AZ
Trades: 1
Quote:
Originally Posted by Zoltar1992 View Post
P.s. I know i could make an array in Php (I think...) and then use a case instead of a for... but the "case" is still Java script, and I vaguely remember there being a php command similar to a case...
but I still want to know for future reference how to embed a language (like javaScript) into a php block, which is in the language itself.
The php case is called a switch:

http://us.php.net/switch
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
thehuskybear is offline
Reply With Quote
View Public Profile Visit thehuskybear's homepage!
 
Reply     « Reply to JavaScript IN php... Help please!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.55305 seconds with 12 queries