Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #7802 > unrolled thread

passing values into javascript

Started byrichard <noreply@example.com>
First post2012-12-14 20:03 -0500
Last post2012-12-19 18:30 -0500
Articles 13 — 7 participants

Back to article view | Back to comp.lang.php


Contents

  passing values into javascript richard <noreply@example.com> - 2012-12-14 20:03 -0500
    Re: passing values into javascript Jerry Stuckle <jstucklex@attglobal.net> - 2012-12-14 21:52 -0500
      Re: passing values into javascript richard <noreply@example.com> - 2012-12-14 22:09 -0500
        Re: passing values into javascript Denis McMahon <denismfmcmahon@gmail.com> - 2012-12-15 13:10 +0000
          Re: passing values into javascript Tim Streater <timstreater@greenbee.net> - 2012-12-15 13:22 +0000
          Re: passing values into javascript Denis McMahon <denismfmcmahon@gmail.com> - 2012-12-15 21:36 +0000
      Re: passing values into javascript Allodoxaphobia <knock_yourself_out@example.net> - 2012-12-15 16:40 +0000
        Re: passing values into javascript Jerry Stuckle <jstucklex@attglobal.net> - 2012-12-15 19:22 -0500
      Re: passing values into javascript richard <noreply@example.com> - 2012-12-15 23:39 -0500
        Re: passing values into javascript "Beauregard T. Shagnasty" <a.nony.mous@example.invalid> - 2012-12-16 06:21 +0000
          Re: passing values into javascript Jerry Stuckle <jstucklex@attglobal.net> - 2012-12-16 09:12 -0500
            Re: passing values into javascript richard <noreply@example.com> - 2012-12-16 13:50 -0500
        Re: passing values into javascript "P E Schoen" <paul@peschoen.com> - 2012-12-19 18:30 -0500

#7802 — passing values into javascript

Fromrichard <noreply@example.com>
Date2012-12-14 20:03 -0500
Subjectpassing values into javascript
Message-ID<14k13t3ghfii5.rtu07anokn7j$.dlg@40tude.net>
<script type="text/javascript">AudioPlayer.embed("audioplayer_1",
{soundFile: "http://mroldies.net/mp3/[value1]-[value2].mp3"})</script>

Given this line of script which is from the wordpress standalone
audioplayer, how could I pass a value from page one to page two so that the
two values in brackets are replaced with the proper information?


http://mroldies.net/1960/all60.html

What I am looking at doing is, linking each song name to one php page.

So that I only have to have one line of code per artist.
Rather than having a single script per song.

I don't care to read your flames on the page showing an under construction
page for most of the links. I have it that way for a reason. Or any of your
other trite little flames that you do just to harass me with.

[toc] | [next] | [standalone]


#7803

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-12-14 21:52 -0500
Message-ID<kagomk$o0$1@dont-email.me>
In reply to#7802
On 12/14/2012 8:03 PM, richard wrote:
> <script type="text/javascript">AudioPlayer.embed("audioplayer_1",
> {soundFile: "http://mroldies.net/mp3/[value1]-[value2].mp3"})</script>
>
> Given this line of script which is from the wordpress standalone
> audioplayer, how could I pass a value from page one to page two so that the
> two values in brackets are replaced with the proper information?
>
>
> http://mroldies.net/1960/all60.html
>
> What I am looking at doing is, linking each song name to one php page.
>
> So that I only have to have one line of code per artist.
> Rather than having a single script per song.
>
> I don't care to read your flames on the page showing an under construction
> page for most of the links. I have it that way for a reason. Or any of your
> other trite little flames that you do just to harass me with.
>

PHP runs on the server, and doesn't know anything about javascript 
(which runs on the client).  The only way PHP can "pass values" to 
javascript is to generate the data in the data which is sent to the client.

But since you're asking about how to do it in wordpress, I would highly 
recommend you ask din a wordpress support group.  They know their code 
better than anyone else, and will know better than anyone else what you 
have to do to get it to work in their environment.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#7804

Fromrichard <noreply@example.com>
Date2012-12-14 22:09 -0500
Message-ID<1c509cnlwc8ky.138l6xvqihkle$.dlg@40tude.net>
In reply to#7803
On Fri, 14 Dec 2012 21:52:58 -0500, Jerry Stuckle wrote:

> On 12/14/2012 8:03 PM, richard wrote:
>> <script type="text/javascript">AudioPlayer.embed("audioplayer_1",
>> {soundFile: "http://mroldies.net/mp3/[value1]-[value2].mp3"})</script>
>>
>> Given this line of script which is from the wordpress standalone
>> audioplayer, how could I pass a value from page one to page two so that the
>> two values in brackets are replaced with the proper information?
>>
>>
>> http://mroldies.net/1960/all60.html
>>
>> What I am looking at doing is, linking each song name to one php page.
>>
>> So that I only have to have one line of code per artist.
>> Rather than having a single script per song.
>>
>> I don't care to read your flames on the page showing an under construction
>> page for most of the links. I have it that way for a reason. Or any of your
>> other trite little flames that you do just to harass me with.
>>
> 
> PHP runs on the server, and doesn't know anything about javascript 
> (which runs on the client).  The only way PHP can "pass values" to 
> javascript is to generate the data in the data which is sent to the client.
> 
> But since you're asking about how to do it in wordpress, I would highly 
> recommend you ask din a wordpress support group.  They know their code 
> better than anyone else, and will know better than anyone else what you 
> have to do to get it to work in their environment.

Wordpress created the script to run outside of it's own format.
Had you bothered to look at the page given, you would see the script in
action. I do not have the fullblown Wordpress stuff on my site.

As PHP creates the html page, it would be, or should be, rather simple to
produce a line of code for that line of JS.
Such as 
Echo "<script>code</script>"

[toc] | [prev] | [next] | [standalone]


#7805

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2012-12-15 13:10 +0000
Message-ID<kahssi$3u7$1@dont-email.me>
In reply to#7804
On Fri, 14 Dec 2012 22:09:12 -0500, richard wrote:

> As PHP creates the html page, it would be, or should be, rather simple
> to produce a line of code for that line of JS.
> Such as Echo "<script>code</script>"

Yep.

Now all you have to do is work out how to get the values you want where 
you have "code".

Simples. Google "javascript variable assignment"

It's probably something like:

echo "<script type='text/javascript'>var jsvarname = {$phpvarname};</
script>\n";

If $phpvarname is a string, you'll need single or escaped double quotes 
round it, either of:

echo "<script type='text/javascript'>var jsvarname = '{$phpvarname}';</
script>\n";

echo "<script type='text/javascript'>var jsvarname = \"{$phpvarname}\";</
script>\n";

If You want to pass the value of a javascript variable from one page to a 
script on another page, then on the first page you need to put the 
variable value into a suitable post or get request (which is a javascript 
issue, not a php issue, so don't ask how to do it here), and then in the 
php you need to extract the value from the request, validate it, and then 
use it for $phpvariable.

How you get it into the post / get request using javascript is a 
javascript topic, not a php one. You might want to google something like 
"dynamically generating get request urls with javascript".

On the php side, you can check that a string in the $_POST or $_GET array 
matches the expected format using a regex:

http://php.net/manual/en/function.preg-match.php

You can convert a string in the $_POST or $_GET array to an int or float 
value using appropriate functions:

http://php.net/manual/en/function.intval.php
http://php.net/manual/en/function.floatval.php

So, for example, as an academic exercise, to read an integer limited to a 
range of 25 .. 75 and with a default value 50 from a get request and send 
it back as a javascript value, you could code something like this in the 
php:

$myval1 = 50; // default value
if ( isset( $_GET['myval1'] ) && preg_match( '/^[2-7][0-9]$/', $_GET
['myval1'] ) == 1 ) {
$myval1 = intval( $_GET['myval1'] );
if ( $myval1 < 25 ) $myval1 = 25; // lower limit value
if ( $myval1 > 75 ) $myval1 = 75; // upper limit value
}

echo "<script type='text/javascript'>\nvar myval1 = {$myval1};\n</script>
\n";

Obviously you also need to make sure that the echo appears at an 
appropriate point in generating the output, I normally try and put such 
things in the document head before I declare any javascript functions.

Rgds

Denis McMahon

[toc] | [prev] | [next] | [standalone]


#7806

FromTim Streater <timstreater@greenbee.net>
Date2012-12-15 13:22 +0000
Message-ID<timstreater-BB3950.13220815122012@news.individual.net>
In reply to#7805
In article <kahssi$3u7$1@dont-email.me>,
 Denis McMahon <denismfmcmahon@gmail.com> wrote:

> On Fri, 14 Dec 2012 22:09:12 -0500, richard wrote:
> 
> > As PHP creates the html page, it would be, or should be, rather simple
> > to produce a line of code for that line of JS.
> > Such as Echo "<script>code</script>"
> 
> Yep.
> 
> Now all you have to do is work out how to get the values you want where 
> you have "code".
> 
> Simples. Google "javascript variable assignment"
> 
> It's probably something like:
> 
> echo "<script type='text/javascript'>var jsvarname = {$phpvarname};</
> script>\n";

Personally I try to keep the PHP part as small as possible, so inside 
the top section of my JS where I'm initialising some variables, it's 
likely to be something like:


var myjsVar = <?php echo $myphpvar; ?> ;


As the man says: simples!

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

[toc] | [prev] | [next] | [standalone]


#7808

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2012-12-15 21:36 +0000
Message-ID<kaiqgi$voh$1@dont-email.me>
In reply to#7805
On Sat, 15 Dec 2012 13:10:42 +0000, Denis McMahon wrote:

> $myval1 = 50; // default value if ( isset( $_GET['myval1'] ) &&
> preg_match( '/^[2-7][0-9]$/', $_GET ['myval1'] ) == 1 ) {
> $myval1 = intval( $_GET['myval1'] );
> if ( $myval1 < 25 ) $myval1 = 25; // lower limit value if ( $myval1 > 75
> )
> $myval1 = 75; // upper limit value }

Typical ballsed up wrapping ...

$myval1 = 50; // default value

// check if a get value was received and that it has the expected
// text format

if ( isset( $_GET['myval1'] ) && preg_match( '/^[2-7][0-9]$/', $_GET
['myval1'] ) == 1 ) {

	$myval1 = intval( $_GET[ 'myval1' ] ); // get the int value

	if ( $myval1 < 25 ) $myval1 = 25; // lower limit value

	if ( $myval1 > 75 ) $myval1 = 75; // upper limit value 

}

Rgds

Denis McMahon

[toc] | [prev] | [next] | [standalone]


#7807

FromAllodoxaphobia <knock_yourself_out@example.net>
Date2012-12-15 16:40 +0000
Message-ID<slrnkcpa04.1p5a.knock_yourself_out@vps.jonz.net>
In reply to#7803
On Fri, 14 Dec 2012 21:52:58 -0500, Jerry Stuckle wrote:
>
> PHP runs on the server, and doesn't know anything about javascript 
> (which runs on the client).  

  (which may or *MAY NOT* be running on the client)

[toc] | [prev] | [next] | [standalone]


#7809

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-12-15 19:22 -0500
Message-ID<kaj480$tc8$1@dont-email.me>
In reply to#7807
On 12/15/2012 11:40 AM, Allodoxaphobia wrote:
> On Fri, 14 Dec 2012 21:52:58 -0500, Jerry Stuckle wrote:
>>
>> PHP runs on the server, and doesn't know anything about javascript
>> (which runs on the client).
>
>    (which may or *MAY NOT* be running on the client)
>

Whether or not it IS running on the client is immaterial. The value is 
still passed via HTML.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#7810

Fromrichard <noreply@example.com>
Date2012-12-15 23:39 -0500
Message-ID<2v0zx3v0t5i5.ivrfh58emm9w$.dlg@40tude.net>
In reply to#7803
On Fri, 14 Dec 2012 21:52:58 -0500, Jerry Stuckle wrote:

> On 12/14/2012 8:03 PM, richard wrote:
>> <script type="text/javascript">AudioPlayer.embed("audioplayer_1",
>> {soundFile: "http://mroldies.net/mp3/[value1]-[value2].mp3"})</script>
>>
>> Given this line of script which is from the wordpress standalone
>> audioplayer, how could I pass a value from page one to page two so that the
>> two values in brackets are replaced with the proper information?
>>
>>
>> http://mroldies.net/1960/all60.html
>>
>> What I am looking at doing is, linking each song name to one php page.
>>
>> So that I only have to have one line of code per artist.
>> Rather than having a single script per song.
>>
>> I don't care to read your flames on the page showing an under construction
>> page for most of the links. I have it that way for a reason. Or any of your
>> other trite little flames that you do just to harass me with.
>>
> 
> PHP runs on the server, and doesn't know anything about javascript 
> (which runs on the client).  The only way PHP can "pass values" to 
> javascript is to generate the data in the data which is sent to the client.
> 
> But since you're asking about how to do it in wordpress, I would highly 
> recommend you ask din a wordpress support group.  They know their code 
> better than anyone else, and will know better than anyone else what you 
> have to do to get it to work in their environment.

FYI, I found the answer at codingforums.
I got it without any BS.

[toc] | [prev] | [next] | [standalone]


#7811

From"Beauregard T. Shagnasty" <a.nony.mous@example.invalid>
Date2012-12-16 06:21 +0000
Message-ID<kajp8o$eqj$2@dont-email.me>
In reply to#7810
richard the sto0pid wrote:

>> On 12/14/2012 8:03 PM, richard the sto0pid wrote:
>>> I don't care to read your flames on the page showing an under
>>> construction page for most of the links. I have it that way for a
>>> reason. Or any of your other trite little flames that you do just to
>>> harass me with.
> [...]
> FYI, I found the answer at codingforums.
> I got it without any BS.

When you asked at that forum, did you include a condescending paragraph 
such as you did here? And usually do when you ask questions?

-- 
   -bts
   -This space for rent, but the price is high

[toc] | [prev] | [next] | [standalone]


#7813

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-12-16 09:12 -0500
Message-ID<kakksn$mkv$1@dont-email.me>
In reply to#7811
On 12/16/2012 1:21 AM, Beauregard T. Shagnasty wrote:
> richard the sto0pid wrote:
>
>>> On 12/14/2012 8:03 PM, richard the sto0pid wrote:
>>>> I don't care to read your flames on the page showing an under
>>>> construction page for most of the links. I have it that way for a
>>>> reason. Or any of your other trite little flames that you do just to
>>>> harass me with.
>> [...]
>> FYI, I found the answer at codingforums.
>> I got it without any BS.
>
> When you asked at that forum, did you include a condescending paragraph
> such as you did here? And usually do when you ask questions?
>

Beauregard, you don't understand.  Richard NEVER does anything wrong - 
the whole of Usenet is against him!

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#7816

Fromrichard <noreply@example.com>
Date2012-12-16 13:50 -0500
Message-ID<l4nhzmt6ojn1.16gr7btns2weo.dlg@40tude.net>
In reply to#7813
On Sun, 16 Dec 2012 09:12:31 -0500, Jerry Stuckle wrote:

> On 12/16/2012 1:21 AM, Beauregard T. Shagnasty wrote:
>> richard the sto0pid wrote:
>>
>>>> On 12/14/2012 8:03 PM, richard the sto0pid wrote:
>>>>> I don't care to read your flames on the page showing an under
>>>>> construction page for most of the links. I have it that way for a
>>>>> reason. Or any of your other trite little flames that you do just to
>>>>> harass me with.
>>> [...]
>>> FYI, I found the answer at codingforums.
>>> I got it without any BS.
>>
>> When you asked at that forum, did you include a condescending paragraph
>> such as you did here? And usually do when you ask questions?
>>
> 
> Beauregard, you don't understand.  Richard NEVER does anything wrong - 
> the whole of Usenet is against him!

nah. just 98%.

[toc] | [prev] | [next] | [standalone]


#7865

From"P E Schoen" <paul@peschoen.com>
Date2012-12-19 18:30 -0500
Message-ID<katinp$e0p$1@dont-email.me>
In reply to#7810
"richard"  wrote in message 
news:2v0zx3v0t5i5.ivrfh58emm9w$.dlg@40tude.net...

> FYI, I found the answer at codingforums.
> I got it without any BS.

So, what is the answer you found? I have a similar need, and although I 
think other replies covered it well enough, I'd appreciate your sharing the 
information, especially if it is any easier.

Thanks,

Paul 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web