Results 1 to 8 of 8

Thread: JS get option value

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517

    JS get option value

    I have the current lists obj in

    tempobj

    I want to get its value, of the selected item.

    so I tried

    tempobj.option(tempobj.selectedIndex)
    and
    tempobj.list(tempobj.selectedIndex)

    How do I get that?

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Array indexing in JavaScript (as in any other C-syntax language) uses [], so it's
    tempobj.options[tempobj.selectedIndex]
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    ah I see. thanks alot beeee

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    do capitals matter in java?

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    cause they really do in perl, and that is an annoyance

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    How come this doesnt work?

    (if the list has '' in the selected item, I want it to speak up)

    <!-- Begin
    function checkrequired(which) {
    var pass=true;
    if (document.images) {
    for (i=0;i<which.length;i++) {
    var tempobj=which.elements[i];
    if (tempobj.name.substring(0,8)=="required") {if (((tempobj.type=='text'||tempobj.type=='textarea')&&tempobj.value=='')||(tempobj.type.toString(0)==' s'&&tempobj.options[tempobj.selectedIndex].value=='')) {
    pass=false;
    break;
    }
    }
    }
    }
    if (!pass) {
    shortFieldName=tempobj.name.substring(8,30).toUpperCase();
    alert("Please make sure the all required fields are completed.");
    return false;
    }
    else
    return true;
    }
    // End -->

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    First, remove the Begin and End words, especially the Begin, it might confuse some engines.

    Second, capitalization matters in JavaScript (again, like in most C-like languages, the only exception I know is PHP), so you'd better get used to it. It's really not that bad.

    Third:
    tempobj.type.toString(0)=='s'
    That's invalid code. type is already a string, so toString doesn't do anything. And toString doesn't take arguments. I guess what you want is
    tempobj.type[0], right?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    oh interesting. thanks ill try that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width