www.webdeveloper.com
Results 1 to 7 of 7

Thread: populate 1 combo box from another

  1. #1
    Join Date
    Aug 2012
    Posts
    3

    populate 1 combo box from another

    I would like to populate a combobox named field_state from another combobox named entry.parent. I would like the value of field_state to equal that of entry.parent. IE both combo boxes have the same lists of data in them preset.

  2. #2
    Join Date
    Aug 2012
    Posts
    3
    Code:
    <html>
     <head>
      <script type="text/javascript">
    
       function changeFunc(a, b, c) {
    	var selectBox1 = document.getElementById("selectBox1");
        var selectBox2 = document.getElementById("selectBox2");
    	var selectBox1Value = selectBox1.value;
        selectBox2.value = selectBox1Value;
       }
    
      </script>
     </head>
     <body>
      <select id="selectBox1" onchange="changeFunc();">
       <option value="1">Option #1</option>
       <option value="2">Option #2</option>
      </select>
      <select id="selectBox2">
       <option value="1">Option #1</option>
       <option value="2">Option #2</option>
      </select>
     </body>
    </html>

  3. #3
    Join Date
    Aug 2012
    Posts
    3
    Is there any way to run the function from the body tag instead of inside the select box tags?

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,356

    Question

    Quote Originally Posted by joesstlouis View Post
    Is there any way to run the function from the body tag instead of inside the select box tags?
    What do you mean by "from the body tag"?

  5. #5
    Join Date
    Aug 2012
    Posts
    3
    <body>

  6. #6
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    We'll leave the body tag alone:
    Quote Originally Posted by joesstlouis View Post
    Is there any way to run the function from the body tag instead of inside the select box tags?
    Code:
    <doctype html>
    <html>
     <head>
     <title>Test</title>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <script type="text/javascript">
    
     (function( m, s )
     {     
       function ih( obj, evt, func )
       {
         obj.attachEvent ? obj.attachEvent( 'on'+evt, func ) : obj.addEventListener( evt, func, false );     
       }
       
       function f()
       {
         var slaveBox = document.getElementById( s );
         
         ih( document.getElementById( m ), 'change', function( elem )
         { 
            slaveBox.value = ( elem.srcElement || elem.target).value;   
         } );   
       }
       
       ih( window, 'load', f );
      
     })( "selectBox1", "selectBox2" );
      
     </script>
     </head>
     <body>
      <select id="selectBox1" >
       <option value="1">Option #1</option>
       <option value="2">Option #2</option>
      </select>
      <select id="selectBox2">
       <option value="1">Option #1</option>
       <option value="2">Option #2</option>
      </select>
     </body>
    </html>
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  7. #7
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,356

    Exclamation

    Quote Originally Posted by joesstlouis View Post
    <body>
    That doesn't help much.
    What is it that you are trying to do?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles