Click to See Complete Forum and Search --> : How to set value?


Shampie
04-28-2003, 04:12 PM
A question concearning the following code
//-- code::
<script>
function tango(){
var weaponArray = new Array(8);
var a = box1.value;
weaponArray[0] = "Item 1", value = 1;
weaponArray[1] = "Item 2", value = 2;
weaponArray[2] = "Item 3", value = 3;
weaponArray[3] = "Item 4", value = 4;
weaponArray[4] = "Item 5", value = 5;
weaponArray[5] = "Item 6", value = "jup";

alert(" current value = "+ value + "");
if(document.all){ ouch.length++; ouch[ouch.length-1].innerText = weaponArray[a]}; return false
}


</script>
<a href="javascript:void(0)" onclick="tango();">Add</a>
<a href="javascript:void(0)" onclick="if(document.all){ if(ouch.length>0){ ouch.length--;}}; return false">Delete</a>

for a somekinda mistake I made the alert message will always give me " current value = jup" no matter which one I add (even a value out of array it will still give me jup!) though what I mean to get is when I add a 1 or a 2 *as value) this should be relatively item 1 and item 2, what do I do wrong?
If there is another way of adding an option (option with a value!) to a list/menu?

please help is welcome! (prefeable anwser in mickymouse style so I am sure to get the point)

havik
04-28-2003, 04:30 PM
To be honest, I don't know what your doing but I can see your problem:

weaponArray[0] = "Item 1", value = 1;
weaponArray[1] = "Item 2", value = 2;
weaponArray[2] = "Item 3", value = 3;
weaponArray[3] = "Item 4", value = 4;
weaponArray[4] = "Item 5", value = 5;
weaponArray[5] = "Item 6", value = "jup";

value = "jup" will erase the previous value so that's why you always get jup.

Havik

Shampie
04-29-2003, 11:40 AM
<select name="weapon2" disabled>
<option value="4">club 1d4</option>
<option value="6">short sword 1d6</option>
<option value="8">scimitar 1d8</option>
<option value="10">long sword 1d10</option>
<option value="12">warhammer 1d12</option>
</select>

this is what a normal drop list looks like (example)
now the value gives the value bounded to it..
for in math if I select option club 1d4 it will give me a value of 4,
and for 1d6 the value will be 6.

What I am trying to do is to get the ability to add a option line via a function
(function blaat(){
add form.weapon2.addoptionline = <option value=14>blaat 1d99</option>
or something..(get the point? adding an option to a drop list) but I dont know the command to add this.. so I tried via a array but this will not allow me to give a value to the option.

Shampie
04-30-2003, 07:22 AM
seems to work pretty good, thank you.

Shampie
04-30-2003, 08:29 AM
seems to be you are a very skiller Javascripter,
It is not my intention to be rude by only asking and not giving..
if you want to know what i'm busy with checkthis (http://members.chello.nl/~r.verbrugge/phpgame/battle.htm) link.

I know it prolly seems basic to you.. but you know I've been busy with javascript for 4 months.. by myself..
ofcourse any advise is never bad and feedback is always good wheater it is good or bad..

Shampie
04-30-2003, 11:47 AM
About this function:

function ichanged(){
if (form.weapon1.selectedValue = "club 1d4"){
form.add1.value = 0;
}
if (form.weapon1.selectedValue = "Dagger 1d6+1"){
form.add1.value = 1;
}
if (form.weapon1.selectedValue = "Dagger 1d6+2"){
form.add1.value = 2;
}
if (form.weapon1.selectedValue = "Dagger 1d6+3"){
form.add1.value = 3;
}
if (form.weapon1.selectedValue = "Dagger 1d6+4"){
form.add1.value = 4;
}
}


Okay, the function is called up when I change the list/menu
I want it to check the one that is selected (by name) since the value is already assigned -->
opt = form.weapon1.options;
opt[opt.length] = new Option("Dagger 1d6+1", "6"); <--

this is what I want:
when "Dagger 1d6+1" is selected, form.add1.value = 1;

so check by list/menu SELECTED not VALUE so obviously the ones I used is wrong.. but what is correct then?

Tnx for you concearn and help

Shampie
04-30-2003, 04:02 PM
If (list/box.selectedweapon = 1d10 + x)
blaat = 10
extra dmg = x

such as that..

since normally a weapon:
1d10 blaat will be 10..
random number between 1&10

but the x... oh muttah.. help..
it'll be solved if I can read the text in the list/box out and from there on determ blaat and x...
:/

AdamBrill
04-30-2003, 04:06 PM
Is this the thread I'm supposed to be helping on? ;)

If I know what you want, try something like this:function ichanged(){
formData = form.weapon1.options[form.weapon1.selectedIndex].innerText;
if (formData == "club 1d4"){
form.add1.value = 0;
}
if (formData == "Dagger 1d6+1"){
form.add1.value = 1;
}
if (formData == "Dagger 1d6+2"){
form.add1.value = 2;
}
if (formData == "Dagger 1d6+3"){
form.add1.value = 3;
}
if (formData == "Dagger 1d6+4"){
form.add1.value = 4;
}
}

Shampie
05-01-2003, 11:28 AM
I have a strong feeling my ful script wont work on anything but IE6.0 tnx for you help all of you!

Shampie
05-01-2003, 02:21 PM
Ok here goes:

function ichanged(){
var serve =0;
form.dex0.value = Math.round(form.dex0.value) + Math.round(form.special1.value);
formData = form.weapon1.options[form.weapon1.selectedIndex].innerText;
if (form.special1.value == 0 && form.special2.value == 0 && form.special3.value == 0){
if (formData == "club 1d4" && form.special1.value < 1 && form.special2.value < 1 && form.special3.value < 1){
form.add1.value = 0;
form.special1.value = 0;
}
else if (formData == "Dagger 1d6+1" ){
form.add1.value = 1;
form.special1.value = 0;
}
else if (formData == "Dagger 1d6+2"){
form.add1.value = 2;
form.special1.value = 0;
}
else if (formData == "Dagger 1d6+3" ){
form.add1.value = 3;
form.special1.value = 0;
}
else if (formData == "Dagger 1d6+3 [Dagger of Speed]" ){
form.add1.value = 3;
form.special1.value = 2;
}}
}

Now.. when I first select the wpn 1d6 +2 form.add1.value = 2,
then when I select wpn 1d6+3 form.add1.value =3 works too..
but when I then try to change it back to 1d6+2 the form.add1.value remains 3!
>> to be continued..

Shampie
05-01-2003, 02:30 PM
function ichanged(){
var serve =0;

form.dex0.value = Math.round(form.dex0.value) + Math.round(form.special1.value);
formData = form.weapon1.options[form.weapon1.selectedIndex].innerText;
if (form.special1.value == 0 && form.special2.value == 0 && form.special3.value == 0){
if (formData == "club 1d4" && form.special1.value < 1 && form.special2.value < 1 && form.special3.value < 1){
form.add1.value = 0;
form.special1.value = 0;
}
if (formData == "Dagger 1d6+1" ){
if (Math.round(form.add1.value < 1)){
form.add1.value = 1;
form.special1.value = 0;
} }
if (formData == "Dagger 1d6+2"){
if (Math.round(form.add1.value < 1)){
form.add1.value = 2;
form.special1.value = 0;
} }
if (formData == "Dagger 1d6+3" ){
if (Math.round(form.add1.value < 1)){
form.add1.value = 3;
form.special1.value = 0;
} }
if (formData == "Dagger 1d6+3 [Dagger of Speed]" ){
if (Math.round(form.add1.value < 1)){
form.add1.value = 3;
form.special1.value = 2;
}
}}
}

I changed the code a bit.. this seems to work a little untill I choose the Dagger 1d6+3 [Dagger of Speed] then the form.add1.value = 3 keeps overruling.. and is unchangeable :| HELP