Hello Everybody,
I need your help to send textbox value linking with href without submitting the form.
Here is the code
<form name="form1" method="post" action="cart.php?action=do&id=<? echo $id; ?>">
<input type="text" style="border:1px solid #8C8B8B;width:60px;height:16px;color:#8C8B8B;padding:1px;font-size:10px;" readonly="readonly" value="<? if(empty($pprice)) echo $product_row['product_price']; else echo $pprice; ?>" id="price" name="price">
<a href="?id=<? echo $id; ?>&imageid=<? echo $nt[id];?>&p=<? $spe=''; echo $spe; ?>" ><img id="<? echo $i; ?>" src="images/<?=$nt[images]?>" width="65" height="45" /></a>
</form>
Now what i want to do that when the image is clicked, it should also take the value of ‘price’ textbox in the same page.
Thanks in Advance.
Immerse
November 25, 2010, 8:42am
2
This is more a job for Javascript than PHP.
Shouldn’t be too hard though. How’s your Javascript knowledge? And where exactly should the <a> tag link to?
Hi Immerse,
<a> tag is link with the image and my javascript is not so good.
Immerse
November 25, 2010, 9:34am
4
Something like this should work, I haven’t tested it though.
<form name="form1" method="post" action="cart.php?action=do&id=<? echo $id; ?>">
<input type="text" style="border:1px solid #8C8B8B;width:60px;height:16px;color:#8C8B8B;padding:1px;font-size:10px;" readonly="readonly" value="<? if(empty($pprice)) echo $product_row['product_price']; else echo $pprice; ?>" id="price" name="price">
<a id="the-link" href="?id=<? echo $id; ?>&imageid=<? echo $nt[id];?>&p=<? $spe=''; echo $spe; ?>" ><img id="<? echo $i; ?>" src="images/<?=$nt[images]?>" width="65" height="45" /></a>
</form>
<script type="text/javascript">
document.getElementById('the-link').onclick = function(e) {
var price = document.getElementById('price').value;
document.location.href = this.href + '&price=' + price;
e.preventDefault();
return false;
}
</script>
Hi Immerse,
Thanks for your answer it works. But I have done like given below:-
[COLOR=“Blue”]<form name=“form1” method=“post” action=“cart.php?action=do&id=<? echo $id; ?>”>
<input type=“text” style=“border:1px solid #8C8B8B ;width:60px;height:16px;color:#8C8B8B ;padding:1px;font-size:10px;” readonly=“readonly” value=“<? if(empty($pprice)) echo $product_row[‘product_price’]; else echo $pprice; ?>” id=“price” name=“price”>
<a href=“?id=<? echo $id; ?>&imageid=<? echo $nt[id];?>&p= " onclick=“this.href+=document.getElementById(‘price’).value; return true;” ><img id=”<? echo $i; ?>" src=“images/<?=$nt[images]?>” width=“65” height=“45” /></a>
</form>[/COLOR]
Both are same.
Thanks again to you Immerse.
Immerse
November 25, 2010, 9:49am
6
Uh yeah, that’s an even shorter solution. Nice one