IMG and onclick?

I've got a form and a text box. That text box is for a number, an inventory. What I want to do is have an image on either side, a decrease and increase. Click the up arrow and in increases the number in the text box. Vice-versa for the decrease arrow.

I can make it work perfectly with a Input type:button, and using the following code in the "onclick":

this.form.[i]textbox[/i].value++;

However, when I want it to run in an IMG tag, it does nothing.

I keep finding articles online about people having problems with it, but no answer to how to fix it. I've tried putting it as calling a function, and wrapping it in a span, a div, and using an anchor with no luck.

Does anyone know how to do what I want? Remember that there are going to be plenty of these on a same page, so as little code would help.

Thank you.

#474453

<a href="../../unavailable.html" onClick="document.whateverform.textbox.value++"><img src="../../unavailable.html"></a>

This should work!!

#474454

Thank you.

But unfortunately, when I click the image, it just sits there thinking, "what if I were a tree?"

#474455

hmmm.... did you try running function instead of accessing the textbox directly?

like

<a href="../../unavailable.html" onClick="valUp()"><img src="../../unavailable.html"></a>

anyway, I tried putting up small HTML file.. and it works. Now I haven't used images. But tag wrapped around image works just like in following html code

<html>
<head>
</head>
<body>
<form name="theForm" method="post" action="">
<input name="numBox" type="text" id="numBox" value="5">
<strong>[<a href="../../unavailable.html" onClick="document.theForm.numBox.value++">+</a>] [<a href="../../unavailable.html" onClick="document.theForm.numBox.value--">-</a>]</strong>
</form>
</body>
</html>

Try copying the above code and pasting it, save as HTML file and run through the browser.

#474461

Oi. While doing a lot of trouble shooting, I found out for some reason, it wasn't recognizing my form name. I am still in the design phase, and I hadn't put an action property yet, apparently that is a prerequisite for the browser to recognize the form. So, when I used "forms[0]" instead, it worked. I just had to add action="" and it took.

Thank you for the help. The code you gave in post #2 works great.

Oi, half a day wasted.

#474465

It happens... Been there, felt that, broke few coffee mugs in frustration. Just to find out a misplaced dot in javascript in the end. :)

#474472