umar
umar

Reputation: 3133

passing value to another page using javascript

Hello every I want to pass a message from php to JavaScript function and then redirecting to another page i want to show that message . Plz help me out . here is the sample code

Php 
if ($result){
$success = "New Page has been added successfully.";
} else {
$error = "Unable to process at this time.";
}

Java script 

<script type="text/javascript">
window.location="admin.php?page=add_user";
</script>

i want this &success message on another page by using this javascript function . i have tried in this way

window.location="admin.php?page=add_user&<?php echo $success?> ";

Upvotes: 0

Views: 2799

Answers (2)

Gaurav Porwal
Gaurav Porwal

Reputation: 513

check this

echo '<script type="text/javascript"> window.location="test.php?page=add_user&msg='. $msg .'"; </script>';

Upvotes: 1

Alex
Alex

Reputation: 6470

Because you have spaces in your response, in order for it to be useful in the url you need to url encode it. See php urlencode function. Also, you have to give name to the query string parameter.

Change you JavaScript like this:

window.location="admin.php?page=add_user&success=<?php echo urlencode($success); ?>";

Upvotes: 1

Related Questions