Open ID Element OnClick

I have a form containing a dynamic dropdown list, where the last dropdown list will contain a MS Office document (i.e. MS Word, MS Excel, etc.). I've tried various ways to have the user click the 'Submit' button and the document opens/displays, however I'm unable to figure out how to display/open the document. Any help is appreciated.

 <form class="form form-horizontal">
      <div class="form-group">
      <label for="company" class="col-sm-2 control-label">Company</label>
      <div class="col-sm-10">
      <select id="company" name="company" class="form-control linked-
      dropdown" data-linked="make">
      <option value="">-- Select Product --</option>
      <option value="1">Product1</option>
      <option value="2">Product2</option>
      <option value="3">Product3</option>
      </select>
      </div>
      </div>
      <div class="form-group">
      <label for="make" class="col-sm-2 control-label">Make</label>
      <div class="col-sm-10">
      <select id="make" name="make" class="form-control linked-dropdown"
      data-linked="model"></select>
      </div>
      </div>
      <div class="form-group">
      <label for="model" class="col-sm-2 control-label">Model</label>
      <div class="col-sm-10">
      <select id="model" name="model" class="form-control"></select>
      </div>
      </div>
      </form>
      <script src="http://code.jquery.com/jquery.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/
      bootstrap.min.js"></script>
      <script>
      var options = {
      make: {
      1:{
      1: 'Prod1Make1',
      2: 'Prod1Make2',
      3: 'Prod1Make3'
      },
     2:{
     4: 'Prod2Make1',
     5: 'Prod2Make2',
     6: 'Prod2Make3'
     },
     3 :{
     7: 'Prod3Make1',
     8: 'Prod3Make2',
     9: 'Prod3Make3'
     }
       },
      model: {
    1: {  
    1: 'Prod1Make1Model1',
    2: 'Prod1Make1Model2',
    3: 'Prod1Make1Model3'
       },
     2: {
     4: 'Prod1Make2Model1',
     5: 'Prod1Make2Model2',
     6: 'Prod1Make2Model3'
      },
      3: {
     7: 'Prod1Make3Model1',
     8: 'Prod1Make3Model2',
     9: 'Prod1Make3Model3'
     },
     4: {
     10: 'Prod2Make1Model1',
     11: 'Prod2Make1Model2',
     12: 'Prod2Make1Model3'
     },
     5: {
     13: 'Prod2Make2Model1',
     14: 'Prod2Make2Model2',
     15: 'Prod2Make2Model3'
     },
     6: {
     16: 'Prod2Make3Model1',
     17: 'Prod2Make3Model2',
     18: 'Prod2Make3Model3'
     },
     7: {
     19: 'Prod3Make1Model1',
     20: 'Prod3Make1Model2',
     21: 'Prod3Make1Model3'
     },
     8: {
     22: 'Prod3Make2Model1',
     23: 'Prod3Make2Model2',
     24: 'Prod3Make2Model3'
     },
     9: {
     25: 'Prod3Make3Model1',
     26: 'Prod3Make3Model2',
     27: 'Prod3Make3Model3'
     }
      }
     };
     </script>
     <script>
        $(function() {
        $('.linked-dropdown').change(function() {
        var linked = $(this).data('linked');
        var target = '#' + linked;
        $(target).empty();
        var child = $(target).data('linked');
        while (child) {
        $('#' + child).empty();
        child = $('#' + child).data('linked');
       }
       var val = $(this).val();
       opts = options[linked][val];
        $(target).append($('<option/>').val('').html('-- Select --'));
       $.each(opts, function(v,o) {
       $(target).append($('<option/>').html(o).val(v))
          });
        });
       });
       </script>

 <button type="button" onClick="document.getElementByid  
     ('model').onclick=model()" class="btn btn-sm btn-
     default">Submit</button>
T SmithAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Leonidas DosasCommented:
function openDoc(url){
  var objword = new ActiveXObject("Word.Application"); 
  if (objword != null) {
    objword.Visible = true;
    objword.Documents.Open(file);
    objword.WindowState = 2;
    objword.WindowState = 1;
  }
}

$('#clickButton').on('click',function(){
  var lastOpt = document.querySelectorAll('select[name="the_name_of_select_element_here"] option:last-child')[0];
  openDoc(lastOpt.value);
});

Open in new window


Note that in the openDoc function you must set the directory path of the document
Leonidas DosasCommented:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
  <form class="form form-horizontal col-sm-9">
    <div class="form-group">
      <label for="company" class="col-sm-2 control-label">Company</label>
      <div class="col-sm-8">
        <select id="company" name="company"  class="form-control linked-dropdown" data-linked="make">
          <option value="">-- Select Product --</option>
          <option value="model1">Product1</option>
          <option value="model2">Product2</option>
          <option value="model3">Product3</option>
        </select>
      </div>
    </div>
    <div class="form-group">
      <label for="make" class="col-sm-2 control-label">Make</label>
      <div class="col-sm-8">
        <select id="make" name="make" class="form-control linked-dropdown" data-linked="model">
            <option value=""></option>
            <option value="make2">Make2</option>
            <option value="make3">Make3</option>
            <option value="make4">Make4</option>
        </select>
      </div>
    </div>
    <div class="form-group">
      <label for="model" class="col-sm-2 control-label">Model</label>
      <div class="col-sm-8">
        <select id="model" name="model" class="form-control">
            <option value=""></option>
            <option value="http://edition.cnn.com/">CNN</option>
            <option value="model3">Model4</option>
            <option value="model4">Model4</option>
        </select>
      </div>
    </div>
  </form>
<script src="http://code.jquery.com/jquery.js"></script>
 
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>




<div class="col-sm-8 col-sm-offset-4">
<button type="button" id="clickButton" class="btn btn-sm btn-default">Submit</button>
</div>
<script>
//    var a;
   function openDoc(url){
        
 window.open(url,"_blank","menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
}

$('#clickButton').on('click',function(){
  var data=new Object;
  $('select').each(function(){
      //console.log($(this));
    data[$(this)["0"].id]=$(this).val();  
  });
  
    openDoc(data.model);
});    
</script>  
</body>
</html>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.