Ham
Ham

Reputation: 814

Convert a hyperlink into a button

In a php page, there is a javascript function at the beginning like this:-

< script type="text/javascript">
    function updatecart(sid,fid,i)
    {
        var qty = document.getElementById(i+"qty").value;
        location.href="index826.php?section=cc&page=cart_update&sid="+sid+"&fid="+fid+"&i="+i+"&qty="+qty;
    }
< /script>

and at bottom, there is a hyperlink that links to the same page, and call the function, like this:-

< input type="text" id="'.$i.'qty" value="'.$qty['qty'].'" size = "4"/>
< a href="#" onclick="updatecart('.$shopid.','.$fid.','.$i.');">Refresh< /a>

Actually, I would like to convert the hyperlink into a normal button like this:-

< input name="button2" type="submit" value="Refresh"/>

Is it possible? Thank you!

Upvotes: 1

Views: 481

Answers (1)

Michael Berkowski
Michael Berkowski

Reputation: 270607

Sure is. Just set the button's onclick and use type='button' rather than submit.

<input name="button2" type="button" value="Refresh" onclick="updatecart('.$shopid.','.$fid.','.$i.');" />

PHP will fill in the values of $shopid, $fid, $i, same as it did with the hyperlink.

Upvotes: 2

Related Questions