OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to change the selected option of a select box onload?

  • Thread starter Thread starter Amrinder Singh
  • Start date Start date
A

Amrinder Singh

Guest
i am working on a project, where i have to select a particular option of a select box, i know how to do this, but the problem is a function must be called whenever value of select box changes, when we do it manually it works, but when i do it with jquery onload, that function not works. Because it only work when a user manually change the option from select box. Please tell me how to do this.

example:

Code:
          <select>
               <option val="0" selected></option>
               <option val="1"></option>
               <option val="2"></option>
               <option val="3"></option>
               <option val="4"></option>
               <option val="5"></option>
          </select>

here is some of my efforts which i have tried:

Code:
$("select").val('5');

<p>i am working on a project, where i have to select a particular option of a select box, i know how to do this, but the problem is a function must be called whenever value of select box changes, when we do it manually it works, but when i do it with jquery onload, that function not works. Because it only work when a user manually change the option from select box. Please tell me how to do this.</p>

<p>example: </p>

<pre><code> <select>
<option val="0" selected></option>
<option val="1"></option>
<option val="2"></option>
<option val="3"></option>
<option val="4"></option>
<option val="5"></option>
</select>
</code></pre>

<p>here is some of my efforts which i have tried:</p>

<pre><code>$("select").val('5');
</code></pre>
 

Latest posts

I
Replies
0
Views
1
impact christian
I
Top