morha13
morha13

Reputation: 1937

How to create button with a link, with variable

I am trying to create button thats redirect me to another page. I am trying to put variable in the link but the button isnt working.

this is my script:

$idSelect[i]="SELECT * FROM times WHERE id=" . $mid[i] . "";
$idResult[i]=mysqli_query($con,$idSelect[i]); 

while($row = mysqli_fetch_array($idResult[i])) {
$uid[i]=$row['userid'];
}

$inc = "in.php?id=". $uid[i] ."";

echo "<input type='submit' value='back' class='button' onclick='window.location.href=". $inc ."'>";

notes:

I tried few tutorials, and I read answers from for the same question but they didnt help

EDIT: I think my mistake is something with the onclick place, but I dont know what is the problem..

Upvotes: 0

Views: 3153

Answers (3)

Channaveer Hakari
Channaveer Hakari

Reputation: 69

Hey use onclick='window.location.replace' as below-

echo "<input type='button' value='back' class='button' onclick='window.location.replace="'. $inc .'"'>";

Upvotes: 0

anurupr
anurupr

Reputation: 2344

You didn't enclose the link.

So your html output would look like this

<input type="submit" value="back" class="button" onclick="window.location.href=in.php?id=1"> 

so javascript will look for a variable called in

This should work

echo "<input type='submit' value='back' class='button' onclick='window.location.href=\"". $inc ."\"'>";

Upvotes: 1

Suman Bogati
Suman Bogati

Reputation: 6349

You can do something like this.

$inc = "http://in.yahoo.com/?p=us";
echo "<input type='submit' value='back' class='button' onclick='redirect()'>";

echo ("<script>
function redirect(){
    window.location.href = '$inc';
}
</script>");

Upvotes: 0

Related Questions