Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript click a value in dropdown list

Tags:

javascript

I have the following code written in HTML:

    <table cellspacing="0" cellpadding="0" width="100%" class="HeaderTable">
    <tbody><tr>
        <td id="dnn_ctr6707_TimeTableView_TdClassesList" class="HeaderClassesCell">
            class
            <select name="dnn$ctr6707$TimeTableView$ClassesList" onchange="javascript:setTimeout(&#39;__doPostBack(\&#39;dnn$ctr6707$TimeTableView$ClassesList\&#39;,\&#39;\&#39;)&#39;, 0)" id="dnn_ctr6707_TimeTableView_ClassesList" class="HeaderClasses">
            <option selected="selected" value="14">a</option>
            <option value="15">b</option>
            <option value="16">c</option>
            <option value="17">d</option>
            <option value="49">e</option>
            <option value="60">f</option>
        </select></td>

What i'm trying to do, is programmly click the option 'b' In the console tab. for some reason it doesn't work for me altho it seems good I think.

Here's what I tried:

var x = document.getElementById('dnn_ctr6707_TimeTableView_ClassesList') // this part work
var y = x.options[1].click() // I managed to get the text of the option but I want it to perform click and it doesn't work that way :(

Thank you for your help!

like image 341
Z.Zadon Avatar asked Dec 17 '22 19:12

Z.Zadon


1 Answers

I think what you want to do is set the value of the select instead of clicking on the option.

Try this instead:

document.getElementById('dnn_ctr6707_TimeTableView_ClassesList').value = "15"
like image 158
pew007 Avatar answered Dec 27 '22 15:12

pew007