juggysingh Posted April 26, 2010 Share Posted April 26, 2010 Hi All,Im trying to make the VALUE element within a form dynamic using JQuery and was wondering if the following is possible and if not what is the way to achive this? <select name="select1" id="select1" size="1"><option value="item_1">Item 1</option><option value="item_2">Item 2</option></select><input type="hidden" name="select1_value" id="select1_value" value="<script>$(document).ready(function(){$(this).text($('#select1').val());});</script>" /> Thanks in advance!! Link to comment Share on other sites More sharing options...
Synook Posted April 26, 2010 Share Posted April 26, 2010 Err, you can't put a tag inside an attribute, and this has no context outside of an event handler. And what do you want to do, anyway? Set an event handler? <script>$(document).ready(function() { $("#select1").bind("change", function() { $('#select1_value').val($(this).val()); });});</script> <select name="select1" id="select1" size="1"><option value="item_1">Item 1</option><option value="item_2">Item 2</option></select><input type="hidden" name="select1_value" id="select1_value" /> Link to comment Share on other sites More sharing options...
juggysingh Posted April 26, 2010 Author Share Posted April 26, 2010 Thanks for your reply!Well, thats a pity, it seems like what im trying to acheive is going to become complicated, at least for me anyway! :SBasically im using JQuery Smart Cart script; http://plugins.jquery.com/project/smartcartAnd i want to add the chosen option from a select to the cart system.DEMO HERE: http://213.175.208.130/~forwarde/index.phpThis is the code which is compliant to execute the function; 'XXX' is equal to the chosen value of the select <div class="scProductListItem"><span>Choose Item</span><select name="select1" id="select1" size="1"><option value="item_1">Item 1</option><option value="item_2">Item 2</option></select><span id="prod_nameXXX">XXX</span><span id="prod_priceXXX"></span><input type="text" name="prod_qty" class="scText" id="prod_qtyXXX" value="1"><input type="button" rel="XXX" class="scItemButton scBtn" value="Add Product"></div> This is my attempt to make it dynamic using JQuery below; <div class="scProductListItem"><span>Choose Item</span><select name="select1" id="select1" size="1"><option value="item_1">Item 1</option><option value="item_2">Item 2</option></select><script>$(document).ready(function(){$("#divselect1").html('<span id="prod_name' +$('#select1').val()+ '">Item Name</span>' + '<br />' +'<span id="prod_price' +$('#select1').val()+ '"></span>' + '<br />' +'<input type="text" name="prod_qty" class="scText" id="prod_qty' +$('#select1').val()+ '" value="1" />' + '<br />' +'<input type="button" rel="' +$('#select1').val()+ '" class="scItemButton scBtn" value="Add Product" />')});</script><div id="divselect1">test</div></div> The above code is not fully functioning as a button as it does not add the item to the cart as the 1st example does! Why is this? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.