/    Sign up×
Community /Pin to ProfileBookmark

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.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@khayman2001authorMar 29.2003 — 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.
Copy linkTweet thisAlerts:
@khayman2001authorMar 29.2003 — 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.
Copy linkTweet thisAlerts:
@khayman2001authorMar 29.2003 — And if you would like to see this in action, go to

[URL=http://www.ravensperch.org/goth/chargen.php]http://www.ravensperch.org/goth/chargen.php[/URL]

But don't submit the form, it doesn't go anywhere yet.
Copy linkTweet thisAlerts:
@khayman2001authorMar 29.2003 — 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!

?
×

Success!

Help @khayman2001 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...