JavaScript How to display fields from select list display fields from table,display fields in lightning component,display

I have done a very long and tedious way of showing details for each option from the select list. I do understand this should not be the way as imagining having to do for hundreds of options. It is simply impractical and a lil daft.

However, at this point in time, I am only testing a logic and have not implemented any data into the database, hence I am not looking at using the 'Select' statement to draw the data out from the database. Hence, I am looking for an alternative java-script for it to read the extra div that will display the details

Code:

select list:

<li class="bigfield">
    <select name =".." id=".." onchange = "return val(this.value);">
        <option value ="0" selected = "selected"> .. </option>
        <option value =".."> .. </option>
        <option value =".."> .. </option>
        <option value = "Others"> Others</option>
    </select>
</li>

Condition that will check which option has been selected:

<script>
function val(x) {
    document.getElementById("extradiv").style.display = x == "Others" ? "block" : "none";
    document.getElementById("..").style.display = x == ".." ? "block" : "none";
}
</script>

This is the long and impractical "extra div block" that displays the each individual different fields when I select either Agency1 or 2 or 3.

<div id = "Agency1" style ="display:none">

      ...
</div>

Hence, How am I able to concise these 3 different option field to just 1 such that in my error_log when the value is POST to the controller when I select Agency 1: It will still display the infos that are associated with Agency 1 and if I select Agency 2, display infos that are associated with Agency 2 etc?

Answer:1

Just try this.,

$(document).ready( function(){
  $('#AgencyDetails').on('change' , function(){
    var val = $(this).val();
    var id =  val.replace(' ','');
    $('.smallfield').hide();
    $('#'+id).show();
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li class="bigfield">
    <select name ="AgencyDetails" id="AgencyDetails">
        <option value ="0" selected = "selected"> Select Agency..</option>
        <option value ="Agency 1"> Agency1</option>
        <option value ="Agency 2"> Agency2</option>
        <option value ="Agency 3"> Agency3</option>
        <option value = "Others"> Others</option>
    </select>
</li>
<div class="smallfield" id = "Agency1" style ="display:none">
    <li class="bigfield"><input value="Agency Name A" type="text" name="agency1Name" id="agency1Name" readonly/></li>
    <li class="bigfield"><input value="Agency Registration Num A" type="text" name="agent1RegistrationNum" id="agent1RegistrationNum" readonly/></li>
    <li class="bigfield"><input value="Agency Address A" type="text" name="agent1Address" id="agent1Address" readonly/></li>
</div>
<div class="smallfield" id = "Agency2" style ="display:none" >
    <li class="bigfield"><input value="Agency Name 2" type="text" name="agency2Name" id="agency2Name" readonly/></li>
    <li class="bigfield"><input value="Agency Registration Num 2" type="text" name="agent2RegistrationNum" id="agent2RegistrationNum" readonly/></li>
    <li class="bigfield"><input value="Agency Address 2" type="text" name="agent2Address" id="agent2Address" readonly/></li>
</div>
<div class="smallfield" id = "Agency3" style ="display:none">
    <li class="bigfield"><input value="Agency Name 3" type="text" name="agency3Name" id="agency3Name" readonly/></li>
    <li class="bigfield"><input value="Agency Registration Num 3" type="text" name="agent3RegistrationNum" id="agent3RegistrationNum" readonly/></li>
    <li class="bigfield"><input value="Agency Address 3" type="text" name="agentAddress" id="agentAddress" readonly/></li>
</div>
Answer:2

Not sure if this is what you wanted.

JQuery

<script>

$(document).ready(function(){

    $('#AgencyDetails').change(function(){

        var id = $(this).val().replace(/\s+/, "");
        console.log(id);

        $("#extradiv").children('div').each(function(){

            if ( $(this).attr("id") == id ) {

                $(this).show();

            } else if ( id == "0" ) {

                $(this).hide();

            } else if ( id == "Others" ) {

                $(this).show();

            } else {

                $(this).hide();

            } 

        })

    });

});

</script>

HTML

<li class="bigfield">
    <select name ="AgencyDetails" id="AgencyDetails">
        <option value ="0" selected = "selected"> Select Agency..</option>
        <option value ="Agency 1"> Agency1</option>
        <option value ="Agency 2"> Agency2</option>
        <option value ="Agency 3"> Agency3</option>
        <option value = "Others"> Others</option>
    </select>
</li>

<div id ="extradiv">

    <div id = "Agency1" style ="display:none">
        <li class="bigfield"><input value="Agency Name A" type="text" name="agency1Name" id="agency1Name" readonly/></li>
        <li class="bigfield"><input value="Agency Registration Num A" type="text" name="agent1RegistrationNum" id="agent1RegistrationNum" readonly/></li>
        <li class="bigfield"><input value="Agency Address A" type="text" name="agent1Address" id="agent1Address" readonly/></li>
    </div>


    <div id = "Agency2" style ="display:none" >
        <li class="bigfield"><input value="Agency Name 2" type="text" name="agency2Name" id="agency2Name" readonly/></li>
        <li class="bigfield"><input value="Agency Registration Num 2" type="text" name="agent2RegistrationNum" id="agent2RegistrationNum" readonly/></li>
        <li class="bigfield"><input value="Agency Address 2" type="text" name="agent2Address" id="agent2Address" readonly/></li>
    </div>


    <div id = "Agency3" style ="display:none">
        <li class="bigfield"><input value="Agency Name 3" type="text" name="agency3Name" id="agency3Name" readonly/></li>
        <li class="bigfield"><input value="Agency Registration Num 3" type="text" name="agent3RegistrationNum" id="agent3RegistrationNum" readonly/></li>
        <li class="bigfield"><input value="Agency Address 3" type="text" name="agentAddress" id="agentAddress" readonly/></li>
    </div>

</div>
Answer:3

I have some element like : <button ng-click="weirdFunction()">Pretty Button</button> And function in controller : $scope.weirdFunction = function(element) { console.log(element); } in ...

I have some element like : <button ng-click="weirdFunction()">Pretty Button</button> And function in controller : $scope.weirdFunction = function(element) { console.log(element); } in ...

  1. element with click event
  2. element click intercepted
  3. element click intercepted selenium
  4. element click intercepted exception
  5. element click
  6. element click javascript
  7. element click intercepted exception selenium
  8. element click intercepted protractor
  9. element click intercepted selenium python
  10. element click intercepted selenium java
  11. element click intercepted selenium c#
  12. element click jquery
  13. element click intercepted error in selenium
  14. element click js
  15. element clickable selenium
  16. element click intercepted python
  17. element click intercepted exception in selenium java
  18. element click web scraper
  19. element.click not working
  20. element click intercepted exception in selenium webdriver

I am working on a plugin for an internal tool that keeps track of how long it takes to work on specific tasks. I am presenting a visual reference of the time its taken but using the timestamps in the ...

I am working on a plugin for an internal tool that keeps track of how long it takes to work on specific tasks. I am presenting a visual reference of the time its taken but using the timestamps in the ...

I have a products array.it consist of name,price,qty. i am Using limitTo When name length reaches to 20. when hover on product how to show full name please hlep me? <p class="hover">{{ item....

I have a products array.it consist of name,price,qty. i am Using limitTo When name length reaches to 20. when hover on product how to show full name please hlep me? <p class="hover">{{ item....

  1. show full name on desktop icons windows 10
  2. show full name iphone messages
  3. show full name on hover
  4. show full name on desktop icons
  5. show full name of file
  6. show full name on desktop icons mac
  7. show full name
  8. show full name in imessage
  9. show full name facebook
  10. show full name in iphone
  11. show full name on whatsapp
  12. show full name email
  13. show full name jira
  14. show full name messages
  15. squeue show full name
  16. show full file name windows 10
  17. big show full name
  18. qstat show full name
  19. show full month name in php
  20. show full file name mac

How do I generate a list, edit some data, and push then it to db? When I hit 'submit', the changes made have no effect. Example: <div id="demo"> <button v-on="click: generateProducts">...

How do I generate a list, edit some data, and push then it to db? When I hit 'submit', the changes made have no effect. Example: <div id="demo"> <button v-on="click: generateProducts">...

  1. laravel update model unique