Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array problem

Status
Not open for further replies.

olivia

Programmer
Apr 10, 2000
8
US
Hi, I have a puzzling problem. I have one array and three forms on one page. The first form displays data 0-52, second 53-189, third 190-end as a select list. When an option in the first form is clicked, it displays the right variables in a text box. However when the options in the second form (53-189) are clicked, it displays the variables associated with data 0-52, not 53-189. I have a separate function for each form, here is the second one.
// specific drug select list
function showData2(joe) {
p = document.joe.drug2.selectedIndex
if (drugs[p].decrease == "" && drugs[p].increase != ""){
result = "Increased PT/INR"
} else if (drugs[p].decrease != "" && drugs[p].increase != "" ){
result = "Both Increased and Decreased PT/INR responses have been reported"
}else if (drugs[p].decrease != "" && drugs[p].increase == "" ){
result = "Decreased PT/INR"
}
document.joe.output2.value = result
}
The forms all have separate names.
I have tried adding for(var p = 53; p < 189; p++) to this and then you get &quot;Decreased PT/INR&quot; for every option which is also incorrect. As far as I can make out, variables for array 0 are being transposed onto 53, 1 for 54 etc etc.
Does anyone have any ideas about this? Thanks very much.


[sig][/sig]
 
The variable 'p' refers to the selectedIndex, which will commence from 0 for each of the select boxes. When you use this to reference the Array you will thus always access the first entry in the Array for the first option in the select box.

Try the following declarations instead:-

p = document.joe.drug2.selectedIndex + 53 for table 2,
p = document.joe.name3.selectedIndex + 190 for table 3.

I think that's gonna nail it! ;-)

[sig][/sig]
 
yes, this is it! it was killing me trying to figure out how script this! My general reference is the JavaScript Bible by Goodman, do you have a suggestion for an additional resource??

again, thanks a million.
 
I can't recommend a better reference resource - it's all down to experience.

With most similar problems you tend to look at it for so long until you really can't see the wood for the trees. When another looks they can sometimes see the solution right away! :)I [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top