Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #16418
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: javascript to php in the same page |
| Date | 2016-02-14 16:43 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <87lh6n44zd.fsf@bsb.me.uk> (permalink) |
| References | <n9pph5$1qss$1@gioia.aioe.org> <87r3gf48b7.fsf@bsb.me.uk> <n9q7f5$gg7$1@gioia.aioe.org> |
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.
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web