I am trying to pass a dynamic value through an anchor tag as if through a submit.
So far I have it working when the href if clicked like so::
html:
<td>
<a href='#' data-val='".$row['client_id']."' class='formAnchor'>
".$row['first_name']. " " .$row['last_name'] ."
</a>
</td>"
js.
$('.formAnchor').on('click', function (e) {
e.preventDefault();
$('#client_id').val($(this).data('val'));
document.getElementById("myForm").submit();
});
So I have a hidden input in my html page and when ever the link (the a tag) is clicked the above javascript first prevents the default action (loading the href location) then appends the value from the a tag to the hidden field then submits the form.
This works when I click the link, it submits the value and I do $_GET['value']
and get the value on the other page.
Now what I can't seem to do is when I try to rightclick the href and open it in new tab it doesn't submit the value as I want it to.
The best example I can think of what I am trying to do would be the way on facebook when you click a profile link (name of the person) it gives you that particular persons profile and it also works when you rightclick and open in new tab.
答案 0 :(得分:0)
我一直在网上进行一些搜索,它刚刚打动了我:由于我期待GET,我可以使用链接,不需要JavaScript:
<td><a href='profile.php?client_id=".$row['client_id']."' data-val='".$row['client_id']."' class='formAnchor'> ".$row['first_name']. " " .$row['last_name'] ."</a></td>"