I have a link and on clicking the link I want to set the value of a flag variable to 1. Is that possible? Like
<a id='ctr' href='#' onclick='flag=1'> Hello </a>
And also how to write the function for the onclick event on the same line, like instead of
<a id='ctr' href='#' onclick='call_this();'> Hello </a>
function call_this(){
flag=1;
}
can I have the call_this function in the onclick line itself?
EDIT2
Now I have the code like this. Inside the onclick event, the value is stored in the $selectedId correctly. But When I try to pass that value in the url, I do not get the correct value. The last value in the for loop is passed.
<script type="text/javascript">
$(document).ready(function(){
<?php foreach ($Forms as $r): ?>
$("<a id='<?php echo $ctr['Form']['id'];?> href='#' onclick='flag=1'> Hello </a>").appendTo("#header").click(function(){
<?php $selectedId=$r['Form']['id'];?>
alert("selId: "+<?php echo $selectedId;?>);//here the selected value is echoed
});
</script>
<a href="http://localhost/Example/new/export?height=220&width=350&id=<?php echo $selectedId;?>" class="thickbox button" title= "Export" >Export</a>
here the id is passed as 4,which is the last value in the php for loop.