javascript update input box value

I have the folling javascript in one of my pages which works correctly whilst it is attached to an input button, when i changed it to an input image the function does not work correctly.

input button:
<INPUT class="KeyboardButton" TYPE="button" value="  1  " onClick="num('1')">

input image:
<INPUT class="KeyboardButton" type="image" src="/admin/epos/images/softkeyboard/btn_1.png" value="  1  " onClick="num('1')">

when you click on the input image to run the javascript function it updates the value in the text box but then submits the form, closing the jQuery modal window it is in.  The input button however updated the text box and keeps the modal screen open, which is the behavior that i would like from the image button.

any ideas?
<script language="JavaScript" type="text/javascript">
<!--
    var field = '';
    function setField(v) {
        field = v;
    }
    function num(v) {
        field.value += v;
    }
    function letter(v) {
        if (v == "")
            field.value = "";
        else if (v == "-") {
            field.value = field.value.substring(0, field.value.length - 1);
        } else
            field.value += v;
    }
//-->
</script>

Open in new window

net-workxAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

StingRaYCommented:
Try this:

<INPUT class="KeyboardButton" type="image" src="/admin/epos/images/softkeyboard/btn_1.png" value="  1  " onClick="num('1');return false;">

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GreggCommented:
How about keeping button and styling it with css? Please check if cross browser compatible.

I hope this helps some.

<html>
<head>
<title></title>
<style type="text/css">
    button {
       background: url(tn/myButtonImage.png) no-repeat;
       width: 50px;
       height: 30px;
       border: 0;
       text-indent: -9999px;
    }
</style>
</head>
<body>
<button value="text" id="btnID" onclick="alert('hi');" />
</body>
</html>

Open in new window

Ramdasa MayyaSenior Software DeveloperCommented:
There is no input type image

you need to use img tag. I sorted out your code to work...

<html>

<script language="JavaScript" type="text/javascript">
<!--
    var field = '';
    function setField(v) {
        field = v;
    }
    function num(v) {
field  = document.getElementById('theField');
        field.value = parseInt(field.value) + parseInt(v);
    }
    function letter(v) {
        if (v == "")
            field.value = "";
        else if (v == "-") {
            field.value = field.value.substring(0, field.value.length - 1);
        } else
            field.value += v;
    }
//-->
</script>
<body>
<form name="myform" id="myform">
<INPUT class="KeyboardButton" TYPE="button" value="1" onClick="num('1')">
<img src="smiley.gif" alt="Smiley face" width="42" height="42" onClick="num('1')"/>
<INPUT class="" TYPE="text" value="1" id="theField">
</form>
</body>
</html>

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.