selenin Posted June 2, 2010 Share Posted June 2, 2010 Hello, I just try to modify a script and I have this problem My Javascript code: <script type="text/javascript"> jQuery(document).ready( function() { catlist(); }); $(document).ready(function(){ $("#pm_sources").change(function () { var str = $("select option:selected").attr('value'); $("#pm_sources_ex").text(str); }) .change(); }); </script> My Template Code: <select name="category" size="1" > <option value="-1">{$lang.select}</option> {foreach from=$categories_list key=k item=v} <option value="{$k}" {if $smarty.post.category == $k}selected{/if}>{$v}</option> {/foreach} </select> <select name="" id="pm_sources" size="1" > <option selected="selected">{$lang.select}</option> {foreach from=$sources key=k item=v} <option value="{$v.url_example}">{$v.source_name|capitalize}</option> {/foreach} </select> <input type="text" name="yt_id" value="{$smarty.post.yt_id}" size="60" class="inputtext" /> <br /><small>Example: <span id="pm_sources_ex"></span></small> My problem is when I put pm_sources before the category it works fine, but like I want to have it like this order it takes for pm_sources_ex the -1 from categories Quote Link to comment Share on other sites More sharing options...
prestonwinfrey Posted June 2, 2010 Share Posted June 2, 2010 Try this: var str = $(this).val(); Quote Link to comment Share on other sites More sharing options...
selenin Posted June 2, 2010 Author Share Posted June 2, 2010 not working, it still takes the the value of the category option Quote Link to comment Share on other sites More sharing options...
prestonwinfrey Posted June 2, 2010 Share Posted June 2, 2010 How about this?: var str = $("#pm_sources:selected").attr('value'); Quote Link to comment Share on other sites More sharing options...
selenin Posted June 2, 2010 Author Share Posted June 2, 2010 no doesn't show anything :'( Quote Link to comment Share on other sites More sharing options...
selenin Posted June 2, 2010 Author Share Posted June 2, 2010 thanks a lot prestonwinfrey got it "#pm_sources option:selected" Quote Link to comment Share on other sites More sharing options...
prestonwinfrey Posted June 2, 2010 Share Posted June 2, 2010 No problem. I was also able to get it to work using what I told you try in my first reply. <html> <head> <title>Select Test</title> <script src="jquery-1.4.2.min.js"></script> <script> $(document).ready(function() { $('#firstSelect').change(function() { alert($(this).val()); }); $('#secondSelect').change(function() { alert($(this).val()); }); }); </script> </head> <body> <select id="firstSelect"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> <select id="secondSelect"> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> </body> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.