Ajax Help needed: can it run via <a> tag, not Form Button?
Posted: Wed Oct 15, 2014 5:21 am
Code: Select all
<script>
function precheck(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("srcHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","/ajax_addtocart.php?q="+str,true);
xmlhttp.send();
}
</script>
<form>
<input type='hidden' name='prodid' value='$row->id'>
<input type='button' value='Request Sample' onclick=\"precheck(prodid.value); document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'\" class='btn_samplecart'>
</form>What I do want to do though, is change it so it runs from an <a> tag, rather than a form button. This is so I can wrap the onclick around an image and information about the product.
I did think of a Javascript in the <a> tag, but that works via a submit, which this isn't.
So how can I wrap this <form> around images, so you "onclick" and it forms the same thing?