Stupid Javascript Question

nvanprooyen

Fortes Fortuna Adiuvat
Dec 8, 2008
3,189
82
0
Orlando, FL
I don't know shit about Javascript and avoid it at pretty much all costs. I have something quick and dirty I need to do with it though and can't figure out what I'm doing wrong. Basically, it's a select box with a handful of options and I want to change the target href based on the value of the selected option. I'm pretty sure I'm doing something stupid here, but I can't figure out what it is....

Code:
<form name="addproducts">
   <select style="padding:3px;position:relative;bottom:10px;" name="sizes">
       <option value="http://www.domain.com/page1.html">Women's Size 5 1/2 - 8 (S)</option>
       <option value="http://www.domain.com/page2.html">Women's Size 8 1/2 - 11 (M)</option>
       <option value="http://www.domain.com/page3.html">Women's Size 11 1/2 and Up (L)</option>
       <option value="http://www.domain.com/page4.html">Men's Size 7 1/2 - 10 (M)</option>
       <option value="http://www.domain.com/page5.html">Men's Size 10 1/2 - 13 (L)</option>
    </select>
    <input type="image" src="images/addToCart_btn.gif" onClick="window.location=document.addproducts.sizes.options[document.addproducts.sizes.selectedIndex].value" name="submit" value="submit"/>
</form>
 


Using jquery:

Code:
<html>
<head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" language="javascript">
        $(document).ready(function() {
            $("#submit").click(function() {
                $("#form").attr("action",$("#sizes").val()); 
                $("#form").submit();                
            });
            });
    </script>
</head>

<form id="form" method="post">
   <select style="padding:3px;position:relative;bottom:10px;" id="sizes">
       <option value="http://www.domain.com/page1.html">Women's Size 5 1/2 - 8 (S)</option>
       <option value="http://www.domain.com/page2.html">Women's Size 8 1/2 - 11 (M)</option>
       <option value="http://www.domain.com/page3.html">Women's Size 11 1/2 and Up (L)</option>
       <option value="http://www.domain.com/page4.html">Men's Size 7 1/2 - 10 (M)</option>
       <option value="http://www.domain.com/page5.html">Men's Size 10 1/2 - 13 (L)</option>
    </select>
    <input type="image" src="images/addToCart_btn.gif" id="submit" value="submit"/>
</form>
<body>
</body>
</html>