Jump to content

Recommended Posts

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...

 

Link to comment
https://forums.phpfreaks.com/topic/231393-variables-jquery/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/231393-variables-jquery/#findComment-1191023
Share on other sites

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/231393-variables-jquery/#findComment-1191050
Share on other sites

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();

Link to comment
https://forums.phpfreaks.com/topic/231393-variables-jquery/#findComment-1191193
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/231393-variables-jquery/#findComment-1191307
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/231393-variables-jquery/#findComment-1191373
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/231393-variables-jquery/#findComment-1191476
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.