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


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

javascript to php in the same page

Started byalex <alex@nomailno.it>
First post2016-02-14 12:48 +0100
Last post2016-08-17 03:23 -0700
Articles 16 — 9 participants

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


Contents

  javascript to php in the same page alex <alex@nomailno.it> - 2016-02-14 12:48 +0100
    Re: javascript to php in the same page Tim Streater <timstreater@greenbee.net> - 2016-02-14 12:12 +0000
    Re: javascript to php in the same page Luuk <luuk@invalid.lan> - 2016-02-14 15:00 +0100
    Re: javascript to php in the same page Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-02-14 15:31 +0000
      Re: javascript to php in the same page alex <alex@nomailno.it> - 2016-02-14 16:45 +0100
        Re: javascript to php in the same page Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-02-14 11:08 -0500
        Re: javascript to php in the same page Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-02-14 16:43 +0000
          Re: javascript to php in the same page Luuk <luuk@invalid.lan> - 2016-02-14 17:50 +0100
            Re: javascript to php in the same page "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-02-14 18:17 +0100
              Re: javascript to php in the same page Luuk <luuk@invalid.lan> - 2016-02-14 19:42 +0100
          Re: javascript to php in the same page Tim Streater <timstreater@greenbee.net> - 2016-02-14 19:21 +0000
            Re: javascript to php in the same page Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-02-14 21:40 +0000
              Re: javascript to php in the same page Erwin Moller <erwinmollerusenet@xs4all.nl> - 2016-02-15 14:49 +0100
                Re: javascript to php in the same page Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-02-15 19:20 +0000
        Re: javascript to php in the same page Arno Welzel <usenet@arnowelzel.de> - 2016-02-15 13:51 +0100
          Re: javascript to php in the same page praider650@gmail.com - 2016-08-17 03:23 -0700

#16412 — javascript to php in the same page

Fromalex <alex@nomailno.it>
Date2016-02-14 12:48 +0100
Subjectjavascript to php in the same page
Message-ID<n9pph5$1qss$1@gioia.aioe.org>
<html>
<body>
Select a file to upload:
<input type="file" id="myFile" onchange="myFunction()" size="50" >
<p id="demo"></p>
<script>
function myFunction() {
var vx = document.getElementById("myFile").value;
document.getElementById("demo").innerHTML = vx;
}
</script>
</body>
</html>

<?php
if (isset($value)){echo $value;}

?>


the variable vx I ned to use in the php $value

when I have this value the all page is loaded so is need to recall the 
page php, but so I lose the value already selected;
I find some solutions: akax, filed hidden, cookie; but not know how use 
in my code

[toc] | [next] | [standalone]


#16413

FromTim Streater <timstreater@greenbee.net>
Date2016-02-14 12:12 +0000
Message-ID<140220161212363220%timstreater@greenbee.net>
In reply to#16412
In article <n9pph5$1qss$1@gioia.aioe.org>, alex <alex@nomailno.it>
wrote:

><html>
><body>
>Select a file to upload:
><input type="file" id="myFile" onchange="myFunction()" size="50" >
><p id="demo"></p>
><script>
>function myFunction() {
>var vx = document.getElementById("myFile").value;
>document.getElementById("demo").innerHTML = vx;
>}
></script>
></body>
></html>
>
><?php
>if (isset($value)){echo $value;}
>
>?>
>
>
>the variable vx I ned to use in the php $value
>
>when I have this value the all page is loaded so is need to recall the 
>page php, but so I lose the value already selected;
>I find some solutions: akax, filed hidden, cookie; but not know how use 
>in my code

A simple ajax example can be found at:

  <http://www.clothears.org.uk>

-- 
"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]


#16414

FromLuuk <luuk@invalid.lan>
Date2016-02-14 15:00 +0100
Message-ID<56c08888$0$23824$e4fe514c@news.xs4all.nl>
In reply to#16412
On 14-02-16 12:48, alex wrote:
> <html>
> <body>
> Select a file to upload:
> <input type="file" id="myFile" onchange="myFunction()" size="50" >
> <p id="demo"></p>
> <script>
> function myFunction() {
> var vx = document.getElementById("myFile").value;
> document.getElementById("demo").innerHTML = vx;
> }
> </script>
> </body>
> </html>
>
> <?php
> if (isset($value)){echo $value;}
>
> ?>
>
>
> the variable vx I ned to use in the php $value
>
> when I have this value the all page is loaded so is need to recall the
> page php, but so I lose the value already selected;
> I find some solutions: akax, filed hidden, cookie; but not know how use
> in my code
>

The output of the php-stuff is 'converted' to 'text' before you can 
press the 'submit' button.

http://php.net/manual/en/intro-whatis.php, says:
What distinguishes PHP from something like client-side JavaScript is 
that the code is executed on the server, generating HTML which is then 
sent to the client. The client would receive the results of running that 
script, but would not know what the underlying code was. You can even 
configure your web server to process all your HTML files with PHP, and 
then there's really no way that users can tell what you have up your 
sleeve.


The documentation is wrong in the part where is claims 'generating HTML'.
The output of the php-code is plain-text, which also might be valid HTML.

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


#16415

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2016-02-14 15:31 +0000
Message-ID<87r3gf48b7.fsf@bsb.me.uk>
In reply to#16412
alex <alex@nomailno.it> writes:

> <html>
> <body>
> Select a file to upload:
> <input type="file" id="myFile" onchange="myFunction()" size="50" >
> <p id="demo"></p>
> <script>
> function myFunction() {
> var vx = document.getElementById("myFile").value;
> document.getElementById("demo").innerHTML = vx;
> }
> </script>
> </body>
> </html>
>
> <?php
> if (isset($value)){echo $value;}
>
> ?>
>
>
> the variable vx I ned to use in the php $value
>
> when I have this value the all page is loaded so is need to recall the
> page php, but so I lose the value already selected;
> I find some solutions: akax, filed hidden, cookie; but not know how
> use in my code

I think you may be gradually going down the wrong path because you are
asking very narrow questions.  This is made worse by the fact that your
questions are not very clear so people are just suggesting thing you
might try rather than guiding you to the best solution.

I suggest you back up a bit.  What are you doing overall?  What is it
you are trying to do that has led you to think that a file control, some
client side script and a bit of PHP is the solution?

-- 
Ben.

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


#16416

Fromalex <alex@nomailno.it>
Date2016-02-14 16:45 +0100
Message-ID<n9q7f5$gg7$1@gioia.aioe.org>
In reply to#16415
<html>
<body>
Select a file to upload:
<input type="file" id="myFile" onchange="myFunction()" size="50" >
<p id="demo"></p>
<script>
function myFunction() {
var vx = document.getElementById("myFile").value;
document.getElementById("demo").innerHTML = vx;
}
</script>
</body>
</html>


with the code above I can select a file in my pc and can have its name 
inner the variable vx;
I need have(to pass) this value (file's name), inner a php variable.


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


#16417

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2016-02-14 11:08 -0500
Message-ID<SD1wy.82585$OT2.54664@fx39.iad>
In reply to#16416
On Sunday February 14 2016 10:45, in comp.lang.php, "alex" <alex@nomailno.it>
wrote:

> <html>
> <body>
> Select a file to upload:
> <input type="file" id="myFile" onchange="myFunction()" size="50" >
> <p id="demo"></p>
> <script>
> function myFunction() {
> var vx = document.getElementById("myFile").value;
> document.getElementById("demo").innerHTML = vx;
> }
> </script>
> </body>
> </html>
> 
> 
> with the code above I can select a file in my pc and can have its name
> inner the variable vx;
> I need have(to pass) this value (file's name), inner a php variable.

If you are not willing to reconsider your design, then...

You need to write your javascript so that it invokes a data transfer to the
webhost where the PHP runs.

On the web-browser side,you will need to
1) write an html <form> that names the target host webpage (where your PHP
   code resides) and invocation method (GET or POST)
2) write javascript to invoke document.<formname>.submit()  (where <formname>
   is the name of the html <form> from step 1

On the web-server side, you will need to write a host webpage in PHP that will
(when run from a GET or a POST) will retrieve the passed data (from the
<form> query, submitted through your javascript) and process it.


-- 
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request

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


#16418

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2016-02-14 16:43 +0000
Message-ID<87lh6n44zd.fsf@bsb.me.uk>
In reply to#16416
alex <alex@nomailno.it> writes:

> <html>
> <body>
> Select a file to upload:
> <input type="file" id="myFile" onchange="myFunction()" size="50" >
> <p id="demo"></p>
> <script>
> function myFunction() {
> var vx = document.getElementById("myFile").value;
> document.getElementById("demo").innerHTML = vx;
> }
> </script>
> </body>
> </html>
>
>
> with the code above I can select a file in my pc and can have its name
> inner the variable vx;
> I need have(to pass) this value (file's name), inner a php variable.

Well that's not really what I was asking but I don't think you are going
to tell me what you are really trying to do.  I have no idea what an
inner variable is -- PHP has variables -- but you can give this value to
a server-side script simply by making the value of a form which gets
submitted:

<!DOCTYPE html>
<html>
  <head>
    <script>
     function myFunction() {
          var vx = document.getElementById("myFile").value;
          document.getElementById("filename").value = vx;
          document.getElementById("name_form").submit();
     }
    </script>
  </head>
  <body>
    Select a file to upload:
    <input type="file" id="myFile" onchange="myFunction()" size="50" >
    <p id="demo"></p>
    <form id="name_form" action="file.php" method=post>
      <input type=text id=filename name=filename
             value="<?= $_POST["filename"] ?>">
    </form>
    File name: <?= $_POST["filename"]; ?>
  </body>
</html>

This omits all kind of important things like quoting and validating the
form contents, checking for errors and so on.

-- 
Ben.

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


#16419

FromLuuk <luuk@invalid.lan>
Date2016-02-14 17:50 +0100
Message-ID<56c0b043$0$23771$e4fe514c@news.xs4all.nl>
In reply to#16418
On 14-02-16 17:43, Ben Bacarisse wrote:
>    File name: <?= $_POST["filename"]; ?>

http://php.net/manual/en/language.basic-syntax.phptags.php
PHP also allows for short open tag <? (which is discouraged since it is 
only available if enabled using the short_open_tag php.ini configuration 
file directive, or if PHP was configured with the --enable-short-tags 
option).

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


#16420

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2016-02-14 18:17 +0100
Message-ID<n9qcr7$940$1@solani.org>
In reply to#16419
Luuk wrote:

> On 14-02-16 17:43, Ben Bacarisse wrote:
>>    File name: <?= $_POST["filename"]; ?>
> 
> http://php.net/manual/en/language.basic-syntax.phptags.php
> PHP also allows for short open tag <? (which is discouraged since it is
> only available if enabled using the short_open_tag php.ini configuration
> file directive, or if PHP was configured with the --enable-short-tags
> option).

This syntax works independently of the setting short_open_tag as of PHP
5.4, see <php.net/ChangeLog-5.php#5.4.0>.

-- 
Christoph M. Becker

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


#16421

FromLuuk <luuk@invalid.lan>
Date2016-02-14 19:42 +0100
Message-ID<56c0ca88$0$23849$e4fe514c@news.xs4all.nl>
In reply to#16420
On 14-02-16 18:17, Christoph M. Becker wrote:
> Luuk wrote:
>
>> On 14-02-16 17:43, Ben Bacarisse wrote:
>>>     File name: <?= $_POST["filename"]; ?>
>>
>> http://php.net/manual/en/language.basic-syntax.phptags.php
>> PHP also allows for short open tag <? (which is discouraged since it is
>> only available if enabled using the short_open_tag php.ini configuration
>> file directive, or if PHP was configured with the --enable-short-tags
>> option).
>
> This syntax works independently of the setting short_open_tag as of PHP
> 5.4, see <php.net/ChangeLog-5.php#5.4.0>.
>

I see that i confused the '<?' with the '<?=' ....

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


#16422

FromTim Streater <timstreater@greenbee.net>
Date2016-02-14 19:21 +0000
Message-ID<140220161921086200%timstreater@greenbee.net>
In reply to#16418
In article <87lh6n44zd.fsf@bsb.me.uk>, Ben Bacarisse
<ben.usenet@bsb.me.uk> wrote:

>to tell me what you are really trying to do.  I have no idea what an
>inner variable is -- PHP has variables -- but you can give this value to

When he says: " ... can have its name inner the variable ... "

he means: " ... can have its name in a variable ... "

That's what my parser says, anyway.

-- 
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

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


#16423

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2016-02-14 21:40 +0000
Message-ID<87ziv3hsxv.fsf@bsb.me.uk>
In reply to#16422
Tim Streater <timstreater@greenbee.net> writes:

> In article <87lh6n44zd.fsf@bsb.me.uk>, Ben Bacarisse
> <ben.usenet@bsb.me.uk> wrote:
>
>>to tell me what you are really trying to do.  I have no idea what an
>>inner variable is -- PHP has variables -- but you can give this value to
>
> When he says: " ... can have its name inner the variable ... "
>
> he means: " ... can have its name in a variable ... "
>
> That's what my parser says, anyway.

Oh yes!  I see.  My dyslexia inserted words to make "inner" parse in
that position, but I see that trying other token would have been better.

-- 
Ben.

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


#16427

FromErwin Moller <erwinmollerusenet@xs4all.nl>
Date2016-02-15 14:49 +0100
Message-ID<56c1d747$0$23747$e4fe514c@news.xs4all.nl>
In reply to#16423
On 2/14/2016 10:40 PM, Ben Bacarisse wrote:
> Tim Streater <timstreater@greenbee.net> writes:
>
>> In article <87lh6n44zd.fsf@bsb.me.uk>, Ben Bacarisse
>> <ben.usenet@bsb.me.uk> wrote:
>>
>>> to tell me what you are really trying to do.  I have no idea what an
>>> inner variable is -- PHP has variables -- but you can give this value to
>>
>> When he says: " ... can have its name inner the variable ... "
>>
>> he means: " ... can have its name in a variable ... "
>>
>> That's what my parser says, anyway.
>
> Oh yes!  I see.  My dyslexia inserted words to make "inner" parse in
> that position, but I see that trying other token would have been better.
>

Just curious...
Can you be a programmer when you "suffer" from dyslexia?

(Sounds like an endless source of confusion to me.
But I don't have dyslexia, so maybe it isn't that bad.)

Regards,
Erwin Moller

-- 
"That which can be asserted without evidence, can be dismissed without 
evidence."
-- Christopher Hitchens

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


#16429

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2016-02-15 19:20 +0000
Message-ID<87d1rx3hnb.fsf@bsb.me.uk>
In reply to#16427
Erwin Moller <erwinmollerusenet@xs4all.nl> writes:

> On 2/14/2016 10:40 PM, Ben Bacarisse wrote:
>> Tim Streater <timstreater@greenbee.net> writes:
>>
>>> In article <87lh6n44zd.fsf@bsb.me.uk>, Ben Bacarisse
>>> <ben.usenet@bsb.me.uk> wrote:
>>>
>>>> to tell me what you are really trying to do.  I have no idea what an
>>>> inner variable is -- PHP has variables -- but you can give this value to
>>>
>>> When he says: " ... can have its name inner the variable ... "
>>>
>>> he means: " ... can have its name in a variable ... "
>>>
>>> That's what my parser says, anyway.
>>
>> Oh yes!  I see.  My dyslexia inserted words to make "inner" parse in
>> that position, but I see that trying other token would have been better.
>>
>
> Just curious...
> Can you be a programmer when you "suffer" from dyslexia?

I think so.  I have a very good eye for syntax and detail, provided it's
not in natural language.  I'll find it hard to see variables that are
misspelled, but that's very rarely been a problem.

Then again (and I am no expert) I suspect there are many closely related
conditions that go by the general term dyslexia, and of course it varies
in how strongly one affected.  Mine is mild, so far as I know.  It's
quite possible that there is a symbol-processing form that would make
programming quite a challenge.

<snip>
-- 
Ben.

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


#16424

FromArno Welzel <usenet@arnowelzel.de>
Date2016-02-15 13:51 +0100
Message-ID<56C1C9E0.5040408@arnowelzel.de>
In reply to#16416
alex schrieb am 2016-02-14 um 16:45:

> <html>
> <body>
> Select a file to upload:
> <input type="file" id="myFile" onchange="myFunction()" size="50" >
> <p id="demo"></p>
> <script>
> function myFunction() {
> var vx = document.getElementById("myFile").value;
> document.getElementById("demo").innerHTML = vx;
> }
> </script>
> </body>
> </html>
> 
> 
> with the code above I can select a file in my pc and can have its name 
> inner the variable vx;

Why is "myFile" not sufficient?

> I need have(to pass) this value (file's name), inner a php variable.

This is already done by the <input type="file"> element! You don't need
*any* JavaScript at all to handle file uploads in PHP.

See here as an example:

<http://www.w3schools.com/php/php_file_upload.asp>


-- 
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
http://fahrradzukunft.de

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


#16933

Frompraider650@gmail.com
Date2016-08-17 03:23 -0700
Message-ID<927b2f7f-3acc-4437-bad5-39891febb25d@googlegroups.com>
In reply to#16424
Exactly!

Why do you even NEED js here?

Use HTML to $GET or $POST input from a form...

and 

direct it to a php script for processing after you hit [ENTER]

[toc] | [prev] | [standalone]


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


csiph-web