0

I am not good in html or JavaScript and I have been trying alot to automatically call the JavaScript function from html drop down. My requirement is to hide the html drop down and hard code the value of drop down and automatically call the function which will query the database on the basis of this hard coded value. Those other retrieved values from db will be used in UI. JavaScript function is :

Behaviour.register({

    '#retailerSelect': function(select) {

        select.onchange = function() {

            if (getValue(select) == ""){
                setValue('query(branch)', "");
                setValue('query(store)', "");
                setValue('query(terminalId)', "");
            }
            this.form.submit();
        }
    },

HTML drop down is :

<td width="33%" align="center" >
            <payo:layout columns="1">
                <payo:cell nowrap="nowrap" align="center">

                    <html:select styleId="retailerSelect" style="margin:2px" property="query(retailer)">
                    <html:option value="1"><bean:message key="tms.dropdown.select.retailer"/></html:option>

                        <c:forEach var="retailer" items="${retailers}">
                            <html:option value="${retailer.id}">${retailer.retailerName}</html:option>
                        </c:forEach> 

                    </html:select>
                </payo:cell>
            </payo:layout>
        </td> 

I need the value of drop down as 1, which will automatically call this onchange function to query the db.

please help,thanks in advance.

1
  • this doesn't look like plain JS. could you please tell what exactly are you using? Commented Jul 25, 2016 at 6:46

2 Answers 2

1

Use onchange to call the function

function selectedNum(number) {
  alert(number);
  }
<select name="numbers" onchange="selectedNum(this.value)"> 
<option value="">Please select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>

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

1 Comment

it does'nt work for me, my function declared looks quiet different.
0

This can be achieved by two ways:

 1. <select id="mySelect"></select>

$('#mySelect').click(function(){
    var value = $(this).val();
    // ajax call
});

2. <select onChange="myFunction(this.value)"></select>

function myFunction(value)
{
    // ajax call
}

Comments

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.