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

Posted on 2005-04-12
Last Modified: 2008-02-01
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)

Question by:williamsF1
    LVL 25

    Accepted Solution

    if(document.form.hidden.length >0)
    var exists = eval(document.form.hidden[i].value)
    var exists = eval(document.form.hidden.value)
    window.alert (exists)     //object
    if(exists) {window.alert ("true")} else {window.alert ("false")}

    Author Comment

    wow, I must be on something.....I thought I tried that?!
    Thank for your help archrajan!
    LVL 25

    Expert Comment

    U r welcome anytime.. thanks for the points!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now