View Full Version : Trouble passing a user defined variable to a form

12-09-2004, 08:57 PM
I'm using the following script to have the user increment and decrement a number. When they are done I need the variable submitted through a form but I can't seem to attach it correctly when I try. What needs to be added so it will pass the value of X when the user hits submit?

<script type="text/javascript">
function updateX(id,number){
var element = document.getElementById(id);
element.innerHTML = element.innerHTML/1+number;

<img style="cursor:pointer;border:none" src="minus.gif" onclick="updateX('x',-1)">
<span style="width:25px;text-align:center;color:red" id="x">0</span>
<img style="cursor:pointer;border:none" src="plus.gif" onclick="updateX('x',+1)">

12-09-2004, 09:09 PM

var element = document.all[id];

12-09-2004, 10:54 PM
That didn't seem to work but I might not have done it correctly. I replaced the var element = line with what you gave me and X still doesn't show up when I submit the form.
From what I've come up with I may have to use a cookie that updates whenever that information is changed then have the action for the form read the data back in and insert it into the database, but I feel that there is most likely an easier way to accomplish this.