473,326 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

need html dropdown to populate javascript variable please

daJunkCollector
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
3 7368
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
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
Awesome guys,

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

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

Similar topics

8
by: adam | last post by:
Hi - im looking to have two drop down boxs one with makes of car and the second drop down box to automatically populate with all the model of that particular make of car. there are about 50 makes...
12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
1
by: middletree | last post by:
For an ASp Intranet app, I have some code that should work, but I am not able to make it happen for some reason, after spending considerable time on this. I am pretty thick when it comes to...
4
by: cjm | last post by:
I have two problems that I suspect will be bread-and-butter problems for the more experienced guys on here, but I'm not the greatest with js. NB: Code snippets at the bottom The first problem...
6
by: passion_to_be_free | last post by:
This is probably simple, but I can't seem to find it anywhere. I have have some values stored in javascript variables. I have a <select> dropdown list whose options correspond to these values. I...
13
by: melih.onvural | last post by:
Group, I'm having a tough time understanding some of the previous posts on this topic so I wanted to write what I've tried and hope that you can help me troubleshoot. I have a dropdown populated...
4
by: anonymous | last post by:
Hi Folks, I have a form with two Dropdown list boxes, which get loaded with data from Database. DropDownList1 gets data from Table1 and DropDownList2 gets data from Table2 Table1 has a...
6
by: daveyand | last post by:
Hey Guys, I've stumped. I created a function that does various things to select boxes. Namely Get All selected indexes, populate array with these values
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.