Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    submiting double combo boxes with descriptions

    I got a Javascript from JavaScript Kit called double combo boxes with description. It fit my application pretty well. I got it working with the data that I wanted to use and it would display just fine. The problem is that this JavaScript program is designed to send the user off to another URL, whereas I just want the information that is in the drop-down boxes to be passed on to the next JSP when I hit submit. It doesn't seem to pass the information, and I'm getting a null pointer exception. I'm new to JavaScript and I don't quite know where to even start to solve this problem. I'm including the relevant code without some of the long lists of data. Any help would be appreciated. Thanks

    function switch_select()
    {
    for (loop = window.document.form_1.select_2.options.length-1; loop > 0; loop--)
    {
    window.document.form_1.select_2.options[loop] = null;
    }

    for (loop = 0; loop < option_array[window.document.form_1.select_1.selectedIndex].length; loop++)
    {
    window.document.form_1.select_2.options[loop] = new Option(option_array[window.document.form_1.select_1.selectedIndex][loop]);
    }

    window.document.form_1.select_2.selectedIndex = 0;
    }

    function switch_text()
    {
    window.document.form_1.textarea_1.value = text_array[window.document.form_1.select_1.selectedIndex][window.document.form_1.select_2.selectedIndex];
    }

    function box()
    {
    if (window.document.form_1.select_2.selectedIndex == 0)
    {
    alert("Where do you think you're going?");
    } else {
    if (open_in_newwindow==1)
    window.open(url_array[window.document.form_1.select_1.selectedIndex][window.document.form_1.select_2.selectedIndex],"_blank");
    else
    window.location=url_array[window.document.form_1.select_1.selectedIndex][window.document.form_1.select_2.selectedIndex]
    }
    }

    function set_orig()
    {
    window.document.form_1.select_1.selectedIndex = 0;
    window.document.form_1.select_2.selectedIndex = 0;
    }

    window.onload=set_orig

    // -->
    </script>


    <!-
    <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
    <html>
    <head>
    <title>CommoditySelect</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    ->

    <body>
    <div align="center">
    <p>&nbsp;</p>
    <form name="form_1" method="post" action="ProcessHData.jsp">
    <p><font size="5">Please select the commodity and strategy you wish to watch.</font></p>
    <p>&nbsp;</p>
    <table width="60%" height="31" border="0">
    <tr>
    <td width="50%" height="26"> <div align="center"><font size="6">
    <select name="select_1" onChange="switch_select(); switch_text();">
    <option value=" " selected>Please Select a Commodity</option>
    <option value="10 Year Treasury Notes">10 Year Treasury Notes</option>
    <option value="30 Year Treasury Bond">30 Year Treasury Bond</option>
    <option value="Cocoa">Cocoa</option>
    <option value="Coffee">Coffee</option>
    <option value="Corn">Corn</option>
    <option value="Cotton">Cotton</option>
    <option value="Crude Oil">Crude Oil</option>
    <option value="Gasoline Unleaded">Gasoline Unleaded</option>
    <option value="Gold">Gold</option>
    <option value="Heating Oil">Heating Oil</option>
    <option value="High Grade Copper">High Grade Copper</option>
    <option value="Japanese Yen">Japanese Yen</option>
    <option value="Lean Hogs">Lean Hogs</option>
    <option value="Live Cattle">Live Cattle</option>
    <option value="Lumber">Lumber</option>
    <option value="NYSE Composite Index">NYSE Composite Index</option>
    <option value="Pork Bellies">Pork Bellies</option>
    <option value="S&amp;P 500 Index">S&amp;P 500 Index</option>
    <option value="Soybean Oil">Soybean Oil</option>
    <option value="Soybeans">Soybeans</option>
    </select>
    </font></div></td>
    <td width="50%"><div align="center"><font size="6">
    <select name="select_2" onChange="switch_text()">
    <option>Please select a strategy.</option>
    <option></option>
    <option></option>
    <option></option>
    </select>
    </font></div></td>
    </tr>
    </table>
    <p><font size="5">
    <input name="textarea_1" type="text" id="textarea_1" size="95">
    </font></p>
    <p><font size="5"> </font></p>
    <p><font size="5">Please select the year you wish to watch</font><font size="5">.</font></p>
    <p>&nbsp;</p>
    <p><font size="5">
    <select name="ContractYear" id="select">
    <option value="1990">1990</option>
    <option value="1991">1991</option>
    <option value="1992">1992</option>
    <option value="1993">1993</option>
    <option value="1994">1994</option>
    <option value="1995">1995</option>
    <option value="1996">1996</option>
    <option value="1997">1997</option>
    <option value="1998">1998</option>
    <option value="1999">1999</option>
    <option value="2000">2000</option>
    <option value="2001">2001</option>
    <option value="2002">2002</option>
    <option value="2003" selected>2003</option>
    <option value="2004">2004</option>
    <option value="2005">2005</option>
    <option value="2006">2006</option>
    <option value="2007">2007</option>
    </select>
    </font></p>
    <p><font size="5"> </font></p>
    <p><font size="5">
    <input type="submit" name="Submit" value="Click to watch the strategy.">
    </font> </p>
    </form>
    <p></p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    </div>
    </body>
    </html>

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Without having read this through too carefully (sorry ) - is it not simply a case of changing this:
    Code:
    function box()
    {
    if (window.document.form_1.select_2.selectedIndex == 0)
    {
    alert("Where do you think you're going?");
    } else {
    if (open_in_newwindow==1)
    window.open(url_array[window.document.form_1.select_1.selectedIndex][window.document.form_1.select_2.selectedIndex],"_blank");
    else
    window.location=url_array[window.document.form_1.select_1.selectedIndex][window.document.form_1.select_2.selectedIndex]
    }
    }
    to this:
    Code:
    function box(){
    if (window.document.form_1.select_2.selectedIndex == 0){
    alert("Where do you think you're going?");
    }
    else{
    window.document.form_1.submit;
    }
    }


    ??

  • #3
    New to the CF scene
    Join Date
    Apr 2003
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Spudhead,
    Thanks for trying, but it still doesn't work. It just doesn't seem to
    want to go to the next page at all. The problem may have nothing to do with the information I'm trying to send to the next page. I have no good way of even determining when and where the error occured. Do you know of a debugger that can handle Java, JSP's and JavaScript? I'm lost.


  •  

    Posting Permissions

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