need html dropdown to populate javascript variable please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • daJunkCollector
    New Member
    • Jun 2007
    • 76

    #1

    need html dropdown to populate javascript variable please

    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.val ue;

    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

    [CODE=html]<body>
    <form name="myForm">
    <TR>
    <TD>Department: </TD>
    <TD>
    <SELECT NAME="departmen t">
    <option value="accounti ng">Accountin g</option>
    <option value="human_re sources">Human Resources</option>
    <option value="informat ion_technology" >Information Technology</option>
    <option value="marketin g">Marketing </option>
    <option value="sales">S ales</option>
    <option value="support staff">Support Staff</option>
    </select>
    </form>
    </TD>
    </TR>
    <form>
    <input type="button" onclick="callEx ternalInterface ()" value="Call ExternalInterfa ce" />
    </form>

    <script>
    var testVar = document.myForm .department.val ue;


    function callExternalInt erface() {
    thisMovie("exte rnalInterfaceEx ample").goHome( testVar);
    }

    function thisMovie(movie Name) {
    if (navigator.appN ame.indexOf("Mi crosoft") != -1) {
    return window[movieName]
    }
    else {
    return document[movieName]
    }
    }
    </script>

    <object classid="clsid: D27CDB6E-AE6D-11cf-96B8-444553540000" id="externalInt erfaceExample" codebase="http://download.macrom edia.com/pub/shockwave/cabs/flash/swflash.cab#ver sion=7,0,19,0" width="550" height="400">
    <param name="movie" value="test.swf " />
    <param name="quality" value="high" />
    <embed src="test.swf" name="externalI nterfaceExample " quality="high" pluginspage="ht tp://www.macromedia. com/go/getflashplayer" type="applicati on/x-shockwave-flash" width="550" height="400"></embed>
    </object>
    </body>[/CODE]
  • akristensen
    New Member
    • Aug 2007
    • 6

    #2
    Change your line 6 in the code to the following:
    [code=html]
    <SELECT NAME="departmen t" onChange="testV ar = this.value">
    [/code]

    That should update the testVar variable whenever the dropdown box changes.

    Comment

    • johnhjohn
      New Member
      • Dec 2006
      • 43

      #3
      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 callExternalInt erface():

      [CODE=javascript]

      <script>
      var testVar;


      function callExternalInt erface() {
      testVar = document.myForm .department.val ue;
      thisMovie("exte rnalInterfaceEx ample").goHome( testVar);
      }

      function thisMovie(movie Name) {
      if (navigator.appN ame.indexOf("Mi crosoft") != -1) {
      return window[movieName]
      }
      else {
      return document[movieName]
      }
      }
      </script>
      [/CODE]

      This way, every time the function callExternalInt erface() is called, the value of testVar is refreshed.

      Comment

      • daJunkCollector
        New Member
        • Jun 2007
        • 76

        #4
        Awesome guys,

        Both solutions are beautiful. Thanks much!

        Comment

        Working...