p4plus2
03-02-2008, 11:12 PM
Hey, I have small problem with this function I am working on. It uses onchange in a select list to modify a area of text(hiding and showing certain text). it is part of a game I am making (mostly in php) but my javascript knowledge is limited so I got most of the function done it just doesn't work :P. but fire bug isn't detecting any errors with it so its a working function just not right I suppose. Here is my function:
function style(){
prefer = document.forms[0].attackstyle.value;
var b = document.getElementById(melee);
var c = document.getElementById(magic);
var d = document.getElementById(range);
if (prefer=='magic'){
b.style.display='none';
c.style.display='inline';
d.style.display='none';
}
else if(prefer=='range'){
b.style.display='none';
c.style.display='none';
d.style.display='inline';
}
else{
b.style.display='inline';
c.style.display='none';
d.style.display='none';
}
return false;
}
And here is the part of the form that calls the function:
<select id="attackstyle" name="style"><option value="melee" selected="melee" onchange="style()">melee</option><option value="range" onchange="style()">range</option><option value="magic" onchange="style()">magic</option></select>
And heres the stuff that the form calls and hides based on changed option:
<div id="melee" class="melee">Enter a strength level</div><div id="range" class="range">Enter a range level</div><div id="magic" class="magic">Enter a magic level</div>
let me know if anything is not clear!
thanks,
~p4plus2~
function style(){
prefer = document.forms[0].attackstyle.value;
var b = document.getElementById(melee);
var c = document.getElementById(magic);
var d = document.getElementById(range);
if (prefer=='magic'){
b.style.display='none';
c.style.display='inline';
d.style.display='none';
}
else if(prefer=='range'){
b.style.display='none';
c.style.display='none';
d.style.display='inline';
}
else{
b.style.display='inline';
c.style.display='none';
d.style.display='none';
}
return false;
}
And here is the part of the form that calls the function:
<select id="attackstyle" name="style"><option value="melee" selected="melee" onchange="style()">melee</option><option value="range" onchange="style()">range</option><option value="magic" onchange="style()">magic</option></select>
And heres the stuff that the form calls and hides based on changed option:
<div id="melee" class="melee">Enter a strength level</div><div id="range" class="range">Enter a range level</div><div id="magic" class="magic">Enter a magic level</div>
let me know if anything is not clear!
thanks,
~p4plus2~