manuelBetancurt
manuelBetancurt

Reputation: 16128

jquery js post variable set and get for post

I need to send some parameters from a php page to another to post email dynamically,

if I send the value as hardcoded is ok, but if i send the value on a textfield, it doesnt work,

here the code

page that request post of mail

<script>
$otroYa = other.val();
console.log (other.val()); //shows value ok of this var!
$.post( "send-mail-parklane-suscrib.php" , {otro: "ss9", otro2: $otroYa });
</script>

so,

otro2 = $otroYa

doesnt get set? , but hardcoding otro, is ok

php page called to perform post

<html>
<head><title>PHP Mail Sender</title></head>
<body>
<?php
session_start(); 
echo("chamb");
$to = '[email protected]';
$from = '[email protected]';
$subject = 'Prklane Financial Subscribe';
$headers = 'From: [email protected]' . "\r\n".
'Reply-To: [email protected]'. "\r\n".
'Return-Path: [email protected]' . "\r\n".
'X-Mailer: PHP/' . phpversion();
$message = "SS9 tkt ss9!!!";
$name=$_POST['otro2'];  
mail($to, $subject, $name, $headers, "-f $from");
?>
</body>
</html>

so if I send my mail with the value

$name=$_POST['otro2'];

is empty

but using the hardcoded

$name=$_POST['otro'];

is ok

how to set the var?

thanks!

Upvotes: 0

Views: 102

Answers (1)

Raptor
Raptor

Reputation: 54212

You mixed up PHP & JavaScript .

Instead of

$otroYa = other.val();

It should be:

var otroYa = other.val();

and the jquery post request should be:

$.post( "send-mail-parklane-suscrib.php" , {otro: "ss9", otro2: otroYa });

Upvotes: 1

Related Questions