Solved

js help with uploadify scriptdata

Posted on 2012-03-15
10
554 Views
Last Modified: 2012-03-21
How can I get the correct value from a dropdown. I can only get the first one in the list. In this case no matter what i select I get albumID=4 as it is the first in the list.

Code from Uploadify
'scriptData'	: {
          "success_action_status"		: "201",
          "userID"                                : "<?= $userID ?>",
	  "albumID"                             : $('#albumID').val()						
},

Open in new window


Code from Dynamic Dropdown
echo "Select an album.<br/>";
echo "<select name='albumID' id='albumID'>";					
while($row = mysql_fetch_array($result)){
      echo "<option value=".$row['id'].">$row[albumName]</option>"; 
}
echo "</select>";

Open in new window


Static view of Dropdown
<select name="albumID" id="albumID">
<option value="4">Game Images</option>
<option value="3">Game Videos</option>
<option value="5">Personal</option>
</select>
0
Comment
Question by:UltraFlux
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 37728990
1. View the source and search for "albumID" to check to make sure there's no other <input> with that same ID.

2. Try:
$('#albumID option:selected').val()
It should be the same thing, but it's a little more defined.

3. If you still get ID=4 after trying #2, then it could be an issue with the timing / order-of-events (e.g. the code is running while the dropdown value has not yet changed to its real value). I'm not sure when the code is running...?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 37729064
>  echo "<option value=".$row['id'].">$row[albumName]</option>";

do you probably want:

    echo "<option value=".$row['id'].">".$row['albumName']."</option>";
0
 

Author Comment

by:UltraFlux
ID: 37733258
Hi gr8gonzo and ahoffann,

Tried
$('#albumID option:selected').val()
Still saved id = 4

Not sure what to do still stuck...
0
Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 37733273
what about my "echo ... " suggestion?
0
 

Author Comment

by:UltraFlux
ID: 37733314
same, no improvement

if($numalbums > 0){
  echo 'Select an album.<br/>';
  echo "<select name='albumID' id='albumID' width='200px'>";					
    while($row = mysql_fetch_array($result)){					
      echo "<option value=".$row['id'].">$row[albumName]</option>"; 
    }
  echo "</select>";
}

Open in new window

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 37734265
please read my suggestion ID: 37729064 again
please make yourself used to the change I suggested, and test it
0
 

Author Comment

by:UltraFlux
ID: 37744420
I did test it as I said above. Nothing changed, still saves id=4
0
 
LVL 35

Accepted Solution

by:
gr8gonzo earned 500 total points
ID: 37744516
Oh I see what's happening. The scriptData is evaluating at the time that the page loads, so it's setting itself to 4 at the beginning of the page load when uploadify is setting up, but when the <select> option changes, you are not sending the updated value back to scriptData, so it stays on the original value at page load.

You'll need to do something like this:

Change: <select name='albumID' id='albumID'>
To: <select name='albumID' id='albumID' onChange="updateScriptData();">

Then add this Javascript function:

function updateScriptData()
{
  // Pull existing settings
  scriptData = $('#file_upload').uploadifySettings('scriptData');

  // Update the album ID to the <select>ed option
  scriptData.albumID = $('#albumID').val();

  // Update the settings
  $('#file_upload').uploadifySettings('scriptData',scriptData);
}

Documentation:
http://www.uploadify.com/documentation/methods/uploadifysettings/
0
 

Author Comment

by:UltraFlux
ID: 37748106
WORKS!
0
 

Author Closing Comment

by:UltraFlux
ID: 37748111
Thanks a lot  gr8gonzo!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question