Multiple onClick="" actions?


I am using this code

<form style="display: none;" name="num1form" id="num1form" action="">
<input type="image" name="1" id="num1" value="1" src="imgl/img_first_01.png" onclick="document.forms[0].action='javascript:ChangeNum1();'"/>

What the above code does is change the action state, it allows me to have multiple image inputs which is great as I can define various inputs with different IDs.

However, this is used for one section of the page I happen to have another <form> with basically the same code but it’s using num2 values, I’m not sure why but I can only using one of these [B]



at a time, for one form only.

Is there anyone able to help me divide this, or make these onClick actions unique so they can be used in more than 1 form?


You’d do better to set the code in the onsubmit handler and then return false so that the action doesn’t run at all. That way you are not trying to stick JavaScript in the action where it doesn’t belong.

Here’s what you can do:

  • Try writing function into which you will pass the objects you intend to process. Just like this

function ChangeNum(object){
//processor codes


This will prevent redundant coding and mop up your code.