dargpat Posted March 22, 2011 Share Posted March 22, 2011 newb here ..... I hope I am in the right forum... What am I doing wrong... <script type="text/javascript"> $(document).ready(function() { var upl = document.getElementById('folder').value; <!--- I NEED THIS VARIABLE TO GO BELOW $('#file_upload').uploadify({ 'uploader' : '/uploadify/uploadify.swf', 'script' : '/uploadify/uploadify.php', 'cancelImg' : '/uploadify/cancel.png', 'fileExt' : '*.jpg', 'folder' : '+upl+', <!--- BUT ITS NOT WORKING! .. 'multi' : true, 'queueSizeLimit' : 10, 'removeCompleted' : true, 'auto' : true }); }); </script> <select id="folder"> <option value="/PATH/TO/SELECTED/CAT" SELECTED>Category</option> </select> The element ID folder should return a path I need. I just need to know how do I call it correctly so that it returns correct path and not empty. I hope someone understands this... Quote Link to comment https://forums.phpfreaks.com/topic/231393-variables-jquery/ Share on other sites More sharing options...
RichardRotterdam Posted March 22, 2011 Share Posted March 22, 2011 why the ' ++ ' wrap? why not simply 'folder' : upl, Quote Link to comment https://forums.phpfreaks.com/topic/231393-variables-jquery/#findComment-1190960 Share on other sites More sharing options...
dargpat Posted March 22, 2011 Author Share Posted March 22, 2011 why the ' ++ ' wrap? why not simply 'folder' : upl, I'm not too keen on java but I tried that also and its not working Quote Link to comment https://forums.phpfreaks.com/topic/231393-variables-jquery/#findComment-1190978 Share on other sites More sharing options...
brianlange Posted March 22, 2011 Share Posted March 22, 2011 You are not accessing the value of the selected option correctly. var selected_index = document.getElementById('folder').selectedIndex; var directory = document.getElementById('folder').options[selected_index].value; You need to get the selected Index value first and the select from the options array. Here's a working example. View source to see the javascript code. http://www.realtown.com/test44.html Quote Link to comment https://forums.phpfreaks.com/topic/231393-variables-jquery/#findComment-1191023 Share on other sites More sharing options...
dargpat Posted March 22, 2011 Author Share Posted March 22, 2011 You are not accessing the value of the selected option correctly. var selected_index = document.getElementById('folder').selectedIndex; var directory = document.getElementById('folder').options[selected_index].value; You need to get the selected Index value first and the select from the options array. Here's a working example. View source to see the javascript code. http://www.realtown.com/test44.html ahhh .. now I understand ... it works ...well sorta! This is what I have! <script type="text/javascript"> $(document).ready(function() { var upl = document.getElementById('folder').selectedIndex; var dir = document.getElementById('folder').options[upl].value; $('#file_upload').uploadify({ 'uploader' : '/uploadify/uploadify.swf', 'script' : '/uploadify/uploadify.php', 'cancelImg' : '/uploadify/cancel.png', 'fileExt' : '*.jpg', 'folder' : dir, 'multi' : true, 'queueSizeLimit' : 10, 'removeCompleted' : true, 'auto' : true }); }); </script> If I use this HTML code where SELECTED is used in OPTIONS list, it returns correct selection: <select id="folder"> <option value="">Choose One</option> <option value="/PATH/TO/DIR" SELECTED>Path 2</option> </select> But if I use this method where SELECTED is not used then it returns nothing as if the function didn't fire! (and it uploads to root folder .. yes its an uploaded if you haven't figured it out) <select id="folder"> <option value="">Choose One</option> <option value="/PATH/TO/DIR">PATH 2</option> </select> In other words its not working when manually selecting an option? what am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/231393-variables-jquery/#findComment-1191050 Share on other sites More sharing options...
RichardRotterdam Posted March 23, 2011 Share Posted March 23, 2011 Don't get the option value simply get the select element value it's way easier. Other then that since you are using jQuery simply use .val(); change this: var upl = document.getElementById('folder').selectedIndex; var dir = document.getElementById('folder').options[upl].value; to: var dir = $('#folder').val(); Quote Link to comment https://forums.phpfreaks.com/topic/231393-variables-jquery/#findComment-1191193 Share on other sites More sharing options...
dargpat Posted March 23, 2011 Author Share Posted March 23, 2011 Don't get the option value simply get the select element value it's way easier. Other then that since you are using jQuery simply use .val(); change this: var upl = document.getElementById('folder').selectedIndex; var dir = document.getElementById('folder').options[upl].value; to: var dir = $('#folder').val(); When I use that DJ it always returned undefined. What I've come to notice using the other method is it always return the first selection value. So its working, its just not returning what I select. Again This works... var upl = document.getElementById('folder').selectedIndex; var dir = document.getElementById('folder').options[upl].value; But it always return the first option value it sees in the dropdown list.. lil more help please... Quote Link to comment https://forums.phpfreaks.com/topic/231393-variables-jquery/#findComment-1191307 Share on other sites More sharing options...
dargpat Posted March 23, 2011 Author Share Posted March 23, 2011 I'm figuring the VALUE to the first selection is set in stone when the page loads. So is there an OnChange script I could use to change the value to the SELECT element when I select a new one? Quote Link to comment https://forums.phpfreaks.com/topic/231393-variables-jquery/#findComment-1191308 Share on other sites More sharing options...
RichardRotterdam Posted March 23, 2011 Share Posted March 23, 2011 Actually the code I pasted did work. It's just that the folder value in the plugin doesn't change when you change the pulldown value. Lemme give you an example that might help you out a bit. Read the code for explanation on what it does. If you understand it you should be able to figure out the whole problem. The following code will alert the chosen value when you change the folder Example <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> // wait till the dom is loaded $(document).ready(function() { // fetch the folder select element var folderMenu = $('#folder'); // when you change the folder do an event folderMenu.change(function() { // fetch the folder that is selected selectedFolder = folderMenu.val(); // alert the current selected folder alert(selectedFolder); }); }); </script> <select id="folder"> <option value="">Choose One</option> <option value="/PATH/TO/DIR1" SELECTED>Path 1</option> <option value="/PATH/TO/DIR2" SELECTED>Path 2</option> <opt Quote Link to comment https://forums.phpfreaks.com/topic/231393-variables-jquery/#findComment-1191373 Share on other sites More sharing options...
dargpat Posted March 23, 2011 Author Share Posted March 23, 2011 Actually the code I pasted did work. It's just that the folder value in the plugin doesn't change when you change the pulldown value. Lemme give you an example that might help you out a bit. Read the code for explanation on what it does. If you understand it you should be able to figure out the whole problem. The following code will alert the chosen value when you change the folder Example <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> // wait till the dom is loaded $(document).ready(function() { // fetch the folder select element var folderMenu = $('#folder'); // when you change the folder do an event folderMenu.change(function() { // fetch the folder that is selected selectedFolder = folderMenu.val(); // alert the current selected folder alert(selectedFolder); }); }); </script> <select id="folder"> <option value="">Choose One</option> <option value="/PATH/TO/DIR1" SELECTED>Path 1</option> <option value="/PATH/TO/DIR2" SELECTED>Path 2</option> <opt Thanks DJ! Actually both of your methods are working! I've come to find out its a bug in a script called uploadify. If you've seen or heard about this bug, please help .. thanks! And thanks again for everyone's help! I've done some research now and I'm not the only one trying to use this script and change the upload directory via dropdown boxes Quote Link to comment https://forums.phpfreaks.com/topic/231393-variables-jquery/#findComment-1191476 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.