0

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?> ";
1
  • Can't you just use PHP to post the data to a different page? Why are you trying to forward with JS? Commented Mar 16, 2011 at 1:44

2 Answers 2

1

check this

echo '<script type="text/javascript"> window.location="test.php?page=add_user&msg='. $msg .'"; </script>';
Sign up to request clarification or add additional context in comments.

Comments

1

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); ?>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.