Reputation: 86
now this is my html button
<html>
<head>
</head>
<body>
<div>
<button type="button">change header</button>
</div
</body></html>
what i want is when i click on it change the variable
example
<?php
$var= "path1";
$new= "path2";
if ( some one clicked the button) !== false) {
$var = $new;
header('Location: $var');
} else {
header('Location: $var');
}
?>
if there is a method with javascript please post it please
Upvotes: 2
Views: 27961
Reputation: 34
<button type="button" id="chnageHeaderbtn">change header</button>
Put in script
$("#chnageHeaderbtn").click(function() {
var prevUrlAddress='http://www.myfirsturl.com';
var chnageUrlAddress='http://www.myurl.com';
window.location.href =chnageUrlAddress;
});
Upvotes: 0
Reputation: 232
<html>
<head>
<script>
function myfunction(){
// no variable needed for this logic
//window.location.replace('the redirect path when button is clicked ')
// example
window.location.replace('newsletter_tb.php');
}
</script>
</head>
<body>
<div>
<button type="button" onclick="myfunction()">change header</button>
</div
</body>
</html>
Using javascript is best for this question
PHP is server side scripting language
Upvotes: 0
Reputation: 15
reko beko@@ see this is hundred percent working
<form action="" method="post">
<input type="hidden" value="t">
<input type="submit" value="change header" name="submit">
</form>
<?php
$var= "hello world";
$new= "i hate world";
if (isset($_POST['submit']) ) {
$var= $new;
echo $var;
} else {
echo $var;
}
?>
Upvotes: 0
Reputation: 752
PHP is server side so it is executed before the page/html is sent to the user. any user interactions are handled by Javascript in the browser. if you wish to change content when a user clicks a button the use javascript event handlers
<html>
<head>
</head>
<body>
<div>
<button type="button" onclick="changeStuff()">change header</button>
</div>
<script>
function changeStuff(){
//change header code
}
</script>
</body></html>
Upvotes: 0
Reputation: 319
<html>
<head>
</head>
<body>
<div>
<button type="button" onClick="function()">change header</button>
</div>
</body></html>
function(){
$var= "hello world";
$new= "i hate world";
$var= $new;
echo $var;
echo $var;
}
Upvotes: 0
Reputation: 7661
With PHP you can try the following:
<form action="" method="post">
<input type="hidden" value="t">
<button>change header</button>
</form>
Add the post check to see if the page is posted.
<?php
$var= "hello world";
$new= "i hate world";
if ( $_POST ) {
$var= $new;
echo $var;
} else {
echo $var;
}
But my guess is that you're really looking for a JS way of doing it.
Upvotes: 2