[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 529
  • Last Modified:

Check if Element Exists problem...if in Array or NOT

There's a web page that querys a list of names, and returns the Name corresponding IDNo.
The IDno is in a Hidden Field.
If there is an array [query returns more than 1 name and 1 IDNo] I have no problem:
var exists = eval(document.form.hidden[i].value)
window.alert (exists)     //object
if(exists) {window.alert ("true")} else {window.alert ("false")}

The problem is when there is only one Name returned from the query hence No array, the above returns an error [Object doesnot support....] and I have to do this:
var exists = eval(document.form.hidden.value)


0
williamsF1
Asked:
williamsF1
  • 2
1 Solution
 
archrajanCommented:
if(document.form.hidden.length >0)
var exists = eval(document.form.hidden[i].value)
else
var exists = eval(document.form.hidden.value)
window.alert (exists)     //object
if(exists) {window.alert ("true")} else {window.alert ("false")}
0
 
williamsF1Author Commented:
wow, I must be on something.....I thought I tried that?!
Thank for your help archrajan!
0
 
archrajanCommented:
U r welcome anytime.. thanks for the points!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now