tags:

views:

33

answers:

1
<?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']?

+3  A: 

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.

Anthony Forloney
the id already echo. but still the link can't found
Jordan Pagaduan
try `onclick="Link(<?php echo $row['id'] ?>)"` without the javascript: it's not needed for onclick= and try doing `var Link = function(id) { ... }` instead of `function Link(id) { ... }`
stagas