JavaScript or Qt way to update an HTML select box value in webkit?
So I have the following HTML and am trying to change which item is selected.
Code:
<select name="coolselectbox">
<option value="default" selected="selected">---</option>
<option value="something">Something</option>
<option value="something-else">Something Else</option>
</select>
Here's what I've tried:
Code:
QWebElement defaultOpt =
this->page()->mainFrame()->findFirstElement("option[value=default]");
QWebelement somethingOpt =
this->page()->mainFrame()->findFirstElement("option[value=something]");
defaultOpt.removeAttribute("selected");
somethingOpt.setAttribute("selected", "selected");
And then also:
Code:
QWebElement selectBox =
this->page()->mainFrame()->findFirstElement("select[name=coolselectbox]");
selectBox.setAttribute("value", "something-else");
However neither of these seems to get the job done, at least visually, however I may have overlooked something.
Does anyone know a Qt solution, or is there perhaps some JavaScript snippet I can run to do this? Also what about a similar approach for radio buttons, which are essentially the same thing?
Re: JavaScript or Qt way to update an HTML select box value in webkit?
I've the exact same problem.
I also tried using ...
Code:
selectBox.setAttribute("value", "something-else");
... which worked fine at inputs. Lost now.
Added after 19 minutes:
Code:
element.evaluateJavaScript("this.selectedIndex = 2");
that works