Jorge
Jorge

Reputation: 5676

PHP javascript link id

<?php
//connect to database .... 
//select query .... 
if(isset($_GET["link"])==false){
echo "sample 1"; 
}else{
echo "sample 2" ;
} 
?>
<script type="javascript">
function Link(id)
{

location.href='linktest.php&link='+id;

}
</script>
<html>
<input type="button" value="link test" onclick="javascript: Link<?php echo $row['id']; ?>"> 
</html>

(assumed question) How do I force the onclick event to contain the value of $row['id']?

Upvotes: 0

Views: 790

Answers (1)

Anthony Forloney
Anthony Forloney

Reputation: 91786

You do not do anything with the value of $row['id'], you need to display it so you need to provide an echo statement.

Therefore, instead of,

onclick="javascript: Link<?php $row['id']; ?>

do this,

onclick="javascript: Link(<?php echo $row['id']; ?>)

As commented, you also forgot parenthesis around the function call.

Upvotes: 3

Related Questions