#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Posts
    181
    Rep Power
    13

    use javascript when click select box


    I have select box like this
    Code:
    SCRIPT LANGUAGE="JavaScript">
    function choose()
    {
    if (document.all.select1.value=="1")
    {
    mypic.src="newsletter_traditional.gif";
    }
    if (document.all.select1.value=="2")
    {
    mypic.src="newsletter_modern.gif";
    }
    }
    </SCRIPT>
    
    <select size=6 name="select1" onchange="choose()" width=100>
    <option value="1" selected>Traditional
    <option value="2">Modern
    </select>
    <img src="newsletter_traditional.gif" name="mypic" border=0>
    This code work. when I click each option. it display own image.

    The problem is when I add tag

    <form action="go.php" method="post">
    and
    </form>

    When I run again. it has error

    I try to assign form name name="form1" and in function choose() I change from

    document.all.select1.value
    to
    document.form1.select1.value
    or
    form1.select1.value

    but it still has error. It tell that undefine mypic vairable. I don't know how to fix it. Please help me.
  2. #2
  3. No Profile Picture
    miaWalczak
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    London
    Posts
    86
    Rep Power
    19
    try

    document.forms['form1'].elements['select1'].value
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    17
    Rep Power
    0
    You can try next construction:
    <script language="JScript">
    selInd = document.all.options.selectedIndex;
    yourVar = document.all.select1.options[selInd].value;
    </script>

    Hope it'll help U

    P.S.: Also try to check accuracy of images urls.
    __________________
    With best regards,
    Julia Pavlova
    Programmer
    Rapid Internet Development
    AlarIT Inc.
    URL: http://www.alarit.com

IMN logo majestic logo threadwatch logo seochat tools logo