javascript en php

Status
Niet open voor verdere reacties.

janusvl

Gebruiker
Lid geworden
11 apr 2009
Berichten
159
hoi

ik heb een variable in javascript en ik wil dat dat een variable word in php. Zijn hier makkelijke mogelijk heden voor

PHP:
<script type="text/javascript">
<!--
function toe(n) {
var reply = prompt("Naam van de website", "")
var reply2 = prompt("Link van de website", "")
var reply3 = prompt("Link van een afbeelding(niet verplicht)", "")
<? 
$test12 = reply;

?>
}
//-->
</script>

ik dacht aan zoiets maar dat zal wel niet werken

ik hoop dat iemand een antwoord heeft janus
 
Niet echt. Op het moment dat de HTML (en dus de javascript code) geladen wordt is het PHP gedeelte al voorbij. De enige manier om dit voor elkaar te krijgen is via AJAX.
 
Via JavaScript je doorsturen naar een andere pagina die het PHP script bevat en dan de variabelen meesturen lijkt mij.

HTML:
<html>

<head>
	<script type="text/javascript">
function toe(n) {
var reply = prompt("Naam van de website", "")
var reply2 = prompt("Link van de website", "")
var reply3 = prompt("Link van een afbeelding(niet verplicht)", "")

		//This function redirects your browser
		function redirect(url)
		{
			window.location = url+"?reply="+reply+ "&reply2="+reply2+ "&reply3="+reply3;
		}
	</script>
</head>

<!-- setTimeout executes the function in the first argument after the time specified in miliseconds (in the second argument) has passed.
Currently this script will direct your to http://google.com a second after the body of this HTML page was completely loaded. 
Replace http://google.com with the URL you want to direct to and you might want to change the redirecting time. -->
<body onLoad="setTimeout('redirect(\' http://google.com \')', 1000)">
</body>

</html>
 
Via JavaScript je doorsturen naar een andere pagina die het PHP script bevat en dan de variabelen meesturen lijkt mij.

HTML:
<html>

<head>
	<script type="text/javascript">
function toe(n) {
var reply = prompt("Naam van de website", "")
var reply2 = prompt("Link van de website", "")
var reply3 = prompt("Link van een afbeelding(niet verplicht)", "")

		//This function redirects your browser
		function redirect(url)
		{
			window.location = url+"?reply="+reply+ "&reply2="+reply2+ "&reply3="+reply3;
		}
	</script>
</head>

<!-- setTimeout executes the function in the first argument after the time specified in miliseconds (in the second argument) has passed.
Currently this script will direct your to http://google.com a second after the body of this HTML page was completely loaded. 
Replace http://google.com with the URL you want to direct to and you might want to change the redirecting time. -->
<body onLoad="setTimeout('redirect(\' http://google.com \')', 1000)">
</body>

</html>

ja bedankt:D had ik net ook gevonden en werkt:D

PHP:
<script language=javascript>
function toe(n){
var naam = prompt("voer de naam van de site in", "")
var link = prompt("voer de link van de site in", "")
var img = prompt("Voeg eventueel een afbeelding toe", "")
document.location.href="index.php?nieuw=1&naam="+naam+"&blad="+n+"&link="+link+"&img="+img;
}
</script>
</head>
<?
if($_GET['nieuw'] == "1"){
$img = $_GET['img'];
$link = $_GET['link'];
$naam = $_GET['naam'];
$blad = $_GET['blad'];

echo $blad." ".$naam." ".$email;

$sql = "UPDATE gadget SET naam='$naam' WHERE email='$email' AND blad='$blad'"; 
      $result = mysql_query($sql); 

}
?>
 
Status
Niet open voor verdere reacties.

Nieuwste berichten

Terug
Bovenaan Onderaan