How to select a child in JS and use the value that assign it to a function?

0
       <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Direct Ship File</a>
            <div class="dropdown-menu" id="dsmenu">
                <a class="dropdown-item" href="#" id="RTB1">RTB1</a>
                <a class="dropdown-item" href="#" id="RTB2">RTB2</a>
            </div>
        </li>
 <ul class="corpoDsfile">
    <br>Provide the orderkey below to retrieve the DirectShip file:
    <br> OrderKey:
    <input type="text" name="orderkey" size="100" id="orderkey" autocomplete="off">
    <input type="submit" onkeyup="upHist()" onkeydown="downHist()" onClick="runOrder()">




$('#dsmenu').children().first().click(function dsFile() {
        $(".corpoDsfile").show();
        $(".corpoReport").hide();
        $(".corpoMonitor").hide();
        console.log("RTB1 foi clicado");
        var appid = "RTB1"
});


$('#dsmenu').children().last().click(function dsFile() {
        $(".corpoDsfile").show();
        $(".corpoReport").hide();
        $(".corpoMonitor").hide();
        console.log("RTB2 foi clicado");
        var appid = "RTB2"

});


    function runOrder(appid) {
        $("#error").hide() // hide the error from any previous execution
        var appid = SE RTB1 FOI CLICADO QUERO QUE O APPID SEJA = RTB1
        var appid = SE RTB2 FOI CLICADO QUERO QUE O APPID SEJA = RTB2
    
asked by anonymous 14.08.2018 / 20:20

1 answer

0

Well, I did not understand your question right, but just click on the div, because the child click is executed first ...

$(function() {

  let appid;

  $('#dsmenu').click(function() {
    runOrder(appid);
  });

  $('#dsmenu').children().first().click(function dsFile() {
    $(".corpoDsfile").show();
    $(".corpoReport").hide();
    $(".corpoMonitor").hide();
    console.log("RTB1 foi clicado");
    appid = "RTB1"
  });

  $('#dsmenu').children().last().click(function dsFile() {
    $(".corpoDsfile").show();
    $(".corpoReport").hide();
    $(".corpoMonitor").hide();
    console.log("RTB2 foi clicado");
    appid = "RTB2"
  });

  function runOrder(appid) {
    $("#error").hide() // hide the error from any previous execution
    console.log('runOrder(appid), appid=',appid);
  }

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><liclass="nav-item dropdown">
  <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Direct Ship File</a>
  <div class="dropdown-menu" id="dsmenu">
    <a class="dropdown-item" href="#" id="RTB1">RTB1</a>
    <a class="dropdown-item" href="#" id="RTB2">RTB2</a>
  </div>
</li>
    
14.08.2018 / 20:37