I have a HTML achor tag like below:
echo '<a href="javascript:tempBuy('.$res_get_price[0][0].','.$res_get_price[0][1].','.$res_get_price[0][2].','.$dt_str.')">'.$res_get_price[0][0];
And the corresponding javascript function tempBuy() is
function tempBuy(rate,veg_name,market_name,dt)
{
alert(dt);
}
But the problem is it does not alert at all ! May be I need to include the variable names within single quotes in tempBuy()
function. I tried tempBuy(\'var1'\,\'var2\'...)
but it shows error. How can I able to to that. Thanks .
Source for the part shows like this:
<td width="120px" class=""><a href="javascript:tempBuy(56.0,Apple,Bangalore,2013-05-18)">56.0</a>
</td>
<script>
function tempBuy(rate,veg_name,market_name,dt)
{
alert(rate);
}
</script>
You didn't wrap your javascript arguments in quotes. You need to wrap each variable in single quotes, since you used double quotes for "href" attribute. Another thing is that you didn't close up "a" HTML tag.
echo '<a href="javascript:tempBuy(\''.$res_get_price[0][0].'\',\''.$res_get_price[0][1].'\',\''.$res_get_price[0][2].'\',\''.$dt_str.'\')">'.$res_get_price[0][0].'</a>';