Click to See Complete Forum and Search --> : weird error


khayman2001
03-29-2003, 05:12 AM
Okay, I'm coding along on a project, and I have an onChange on a select form input. It is supposed to check the current value, then do a test, and is supposed to change the value of a text input, but all I get is NaN in the changed field. The code follows. Any help would be appreciated.

// function for checking the skill point value onChange.
function SkillChange(value, new_value)
{
if (value < new_value)
{
change = new_value - value;
document.char.skill_points.value = skill_points - change;
}
else
{
if (value > new_value)
{
change = value - new_value;
really_new_value = skill_points + change;
document.char.skill_points.value = really_new_value;
}
else
{
return true;
}
}
}

// vars for skills
var accessorize = "";


And then in the body I have this:

<form name="char">

Accessorize: <select name="accessorize" onChange="SkillChange(accessorize, window.document.char.accessorize.options[selectedIndex].text);">
<option value="0">0
<option value="1">1
<option value="2">2
<option value="3">3
</select>

<input type="text" size="3" readonly="readonly" value="10" name="skill_points">

</form>

I've tried tons of things in the accessorize variable, and they all give me a stupid "document.char.accessorize is null or not an object" error. I've also tried putting the accessorize statement after the form, and still get the error. I'm going even further out of my mind trying to work with this.

khayman2001
03-29-2003, 11:24 AM
Thanks, that helped a lot. I actually realized that I was trying to use a global variable name due to your post, and switched it to accessorize_skill for the var name. Now I have another problem, though. I want to change the value of the variable that I feed into the function as the value argument. I can't figure anything out. Basically, when you select 2, I want the value in the final box to be 8, then when you switch that same 2 to a 1, I want the value to be 9 in the final box, and when you select 3 in a different select, I want the number in the final box to be 6. I've already used return skill_points for the final box, but can't work out the if then argument for adding the number back. If you need an explanation a little less confusing, I'll try and rephrase.

khayman2001
03-29-2003, 11:28 AM
I just realized that I hadn't included this in the previous code:

// starting number of skill points
var skill_points = 10;

And then I realized that that variable was the same as a form element, so I switched all occurences of that var with skill_points_value.

khayman2001
03-29-2003, 11:30 AM
And if you would like to see this in action, go to

http://www.ravensperch.org/goth/chargen.php

But don't submit the form, it doesn't go anywhere yet.

khayman2001
03-29-2003, 12:13 PM
Actually, that's pretty much precisely what I'm trying to do, and I even posted a question on here for a supposed select element (little did I know it wasn't one, just a Windows' specific little bugger) such as the one you've re-created with the + and - so, that'll work great, thanks!

:D