Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
selecting the dropdown from an page loaded through a div

I am loading a page through a div because of iframe restrictions. What I want to do is access the page contents and select the first item in the dropdown. If the id of the dropdown is called myDropdown or something like "ctl00_ctl65_g_549adf60_cb6b_4794_af15_99ce724b040f_FormControl0_V1_I1_D2", how do i access this to select.

$(document).ready(function() {
  $("#load_home").on("click", function() {
    $("#content").load("https://page.aspx");
  });
});
<div id="topBar">
  <a href="#" id="load_home"> Rate!</a>
</div>
<div id="content">
</div>
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Try this script.

    var interval;
    $(document).ready(function () {
        $("#load_home").on("click", function () {
            $('.calc-loader').show();
            $("#content").load("HtmlPage5.html");

            interval = setInterval(function () {
                console.log($('#content select option').length);
                if ($('#content select option').length > 2) {
                    clearInterval(interval);
                    $('.calc-loader').hide();
                    $('#content select option:eq(3)').prop("selected",true);
                    $('#content select').trigger('change');
                }
            }, 1000);
        });
    });
about 4 years ago · Santiago Trujillo Report

0

You need to access it in the .load callback or delegate:

$(function() {
  $("#load_home").on("click", function() {
    $("#content").load("https://page.aspx",function() {
      $("#myDropdown option:eq(2)").prop{"selected",true);
      // if you have event handlers on the select, you want to trigger them
      $("#myDropdown").change(); 
    });
  });
});

Delegation:

$("#content").on("change","#myDropdown",function() {
  // delegated the change event to the container
});
about 4 years ago · Santiago Trujillo Report

0

Here is a modular findAndSelect() function using pure JS. Parameters are the string ID of the select, and the string value of the option you want to select.

Say your html is : <select id="sel"><option>option1</option></select> and you want to set #sel to 'option1', you call findAndSelect('sel','option1');

function findAndSelect (elementId, optionToSelect) {

  function findRelevantIndex(elementId) {
    var optionsArr = document.getElementById(elementId).options;
    var optionsLen = optionsArr.length;
    for (var i = 0; i < optionsLen; i++) {
      if (optionsArr[i].text == optionToSelect) {
        return i;
      }
    }
    console.log('found no matching option as ' + optionToSelect);
    return 0;
  }
  document.getElementById(elementId).selectedIndex = findRelevantIndex(elementId);
  console.log('new selected index for ' + elementId + ' is ' + document.getElementById(elementId).selectedIndex);
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!