0

Function1 calls showCyclists() by calling, at the end of function1, using a parameter, showCyclists(country.id). This launches the showCylists function.

    function showCyclists(countryID){  //creates a table with athlete of country
        function cyclistOrder() { //checks on change select box and appends to sort
            sql="SELECT name, ISO_id, height, weight, gender FROM `Cyclist`"; //get info from cyclist db

            select = document.getElementById("selectCycle")

            if(select.value == "height"){
                sql += " ORDER BY height ";
            }

            return sql;
        }
//continue with showCyclists()

I need to find a way to execute this function with the same parameter (country id) on change of a select box.

Obviously I can't do <select id="selectCycle" class="select-cycle" onchange="showCyclists()"> because I'd be calling my function with no parameter.

How can I solve this? Thanks in advance

5
  • onchange="showCyclists(value)" Commented Mar 27, 2017 at 18:03
  • That doesnt work. it calls the function with as a parameter value, when it should be a country ID that is acquired in function1. Commented Mar 27, 2017 at 18:04
  • i don't see function1, but if it wraps the other, you can just use closure to reach the parameter... Commented Mar 27, 2017 at 18:06
  • They arent nested functions. Commented Mar 27, 2017 at 18:09
  • pass the value or use bind() to set this or an argument from the caller Commented Mar 27, 2017 at 18:11

1 Answer 1

1

modify the onchange="showCyclists() to onchange="showCyclists(this) then you have access the parameter you need as this.options[this.selectedIndex].value inside the function. You will need to put the right countryID in the value declaration of each select option.

Sign up to request clarification or add additional context in comments.

3 Comments

missing a .target?
What is e meant to be?
e was a typo for this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.