By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,185 Members | 667 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,185 IT Pros & Developers. It's quick & easy.

need html dropdown to populate javascript variable please

daJunkCollector
P: 76
I have the html/javascript posted below, I imagine the fix to my problem is something simple that I am overlooking. My script is a little bit of html and javascript, and there is an embedded flash file written in actionscript. This is a test page, and I am furious that it is posing such a problem.

I am communicating between the html and flash object. My goal is to populate the flash object textbox with the value of the html combobox (I know this is silly, but again its a test that is going to lead up to a much more involved project).

So, the javascript below works to a certain extent...

The problem is with the line: var testVar = document.myForm.department.value;

I want the variable, testVar, to equal the value of which ever option the user selects from the combobox. The way it is setup now, the variable will not update! (it will only send the initial value to flash i.e. "Accounting").

Check it out online! http://www.dajunkyard.com/USGtestser...ceExample.html

Expand|Select|Wrap|Line Numbers
  1. <body>
  2.     <form name="myForm">
  3.         <TR>
  4.             <TD>Department:</TD>
  5.             <TD>
  6.                   <SELECT NAME="department">
  7.                 <option value="accounting">Accounting</option>
  8.                 <option value="human_resources">Human Resources</option>
  9.                 <option value="information_technology">Information Technology</option>
  10.                 <option value="marketing">Marketing</option>
  11.                 <option value="sales">Sales</option>
  12.                 <option value="support staff">Support Staff</option>
  13.                 </select>
  14.     </form>
  15.         </TD>
  16.       </TR>
  17. <form>
  18.     <input type="button" onclick="callExternalInterface()" value="Call ExternalInterface" />
  19. </form>
  20.  
  21. <script>
  22. var testVar = document.myForm.department.value;
  23.  
  24.  
  25. function callExternalInterface() {
  26.     thisMovie("externalInterfaceExample").goHome(testVar);
  27. }
  28.  
  29. function thisMovie(movieName) {
  30.     if (navigator.appName.indexOf("Microsoft") != -1) {
  31.         return window[movieName]
  32.     }
  33.     else {
  34.         return document[movieName]
  35.     }
  36. }
  37. </script>
  38.  
  39. <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="externalInterfaceExample" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="550" height="400">
  40.       <param name="movie" value="test.swf" />
  41.       <param name="quality" value="high" />
  42.       <embed src="test.swf" name="externalInterfaceExample" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="550" height="400"></embed>
  43. </object>
  44. </body>
Aug 16 '07 #1
Share this Question
Share on Google+
3 Replies

P: 6
Change your line 6 in the code to the following:
Expand|Select|Wrap|Line Numbers
  1.             <SELECT NAME="department" onChange="testVar = this.value">
  2.  
That should update the testVar variable whenever the dropdown box changes.
Aug 16 '07 #2

P: 43
The reason the value of testVar doesn't change is because it is only told to find the value of the dropdown list when the page loads. To fix this, place the variable inside of the function callExternalInterface():

Expand|Select|Wrap|Line Numbers
  1.  
  2. <script>
  3. var testVar;
  4.  
  5.  
  6. function callExternalInterface() {
  7. testVar = document.myForm.department.value;
  8.     thisMovie("externalInterfaceExample").goHome(testVar);
  9. }
  10.  
  11. function thisMovie(movieName) {
  12.     if (navigator.appName.indexOf("Microsoft") != -1) {
  13.         return window[movieName]
  14.     }
  15.     else {
  16.         return document[movieName]
  17.     }
  18. }
  19. </script>
  20.  
This way, every time the function callExternalInterface() is called, the value of testVar is refreshed.
Aug 16 '07 #3

daJunkCollector
P: 76
Awesome guys,

Both solutions are beautiful. Thanks much!
Aug 17 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.