Click here to Skip to main content
14,699,081 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi.....I am trying to fetch the id from database on click of an image and assigning it to a element and trying to print that id in javascript. When i print it does not gives me error but written output as "undefined".

What I have tried:

This is my PHP Code:


';
echo "";
while($result=mysql_fetch_array($que))
{

echo " ";
echo  ' ';
 $idee=$result['Id'];

 echo $idee;
 
 echo ''.'<a href=""></a>'.'';
 $count++;
 echo " ";
if($count%3==0)
echo "";
}
echo "";
}
?>





And this is my Javascript code:




function fun()
{
document.write(document.getElementById("show").value);

  
        
alert("welcomee");
}
Posted
Updated 9-Jul-20 17:45pm
v3

1 solution

Your code is very vague but you can try something like this -
<input type="text" id="show" value="<?PHP echo $idee; ?>" />

function fun()
{
var show = document.getElementById("show").value);

if (show == "") {
    alert("PHP did not load the id");
} else {
    alert(show);  
        
    alert("welcomee");
}
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900