Results 1 to 2 of 2

Thread: JavaScript or Qt way to update an HTML select box value in webkit?

  1. #1
    Join Date
    Apr 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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.

    HTML Code:
    1. <select name="coolselectbox">
    2. <option value="default" selected="selected">---</option>
    3. <option value="something">Something</option>
    4. <option value="something-else">Something Else</option>
    5. </select>
    To copy to clipboard, switch view to plain text mode 

    Here's what I've tried:

    Cpp Code:
    1. QWebElement defaultOpt =
    2. this->page()->mainFrame()->findFirstElement("option[value=default]");
    3.  
    4. QWebelement somethingOpt =
    5. this->page()->mainFrame()->findFirstElement("option[value=something]");
    6.  
    7. defaultOpt.removeAttribute("selected");
    8. somethingOpt.setAttribute("selected", "selected");
    To copy to clipboard, switch view to plain text mode 

    And then also:

    Cpp Code:
    1. QWebElement selectBox =
    2. this->page()->mainFrame()->findFirstElement("select[name=coolselectbox]");
    3.  
    4. selectBox.setAttribute("value", "something-else");
    To copy to clipboard, switch view to plain text mode 


    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?

  2. #2
    Join Date
    Apr 2010
    Posts
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: JavaScript or Qt way to update an HTML select box value in webkit?

    I've the exact same problem.

    I also tried using ...

    Qt Code:
    1. selectBox.setAttribute("value", "something-else");
    To copy to clipboard, switch view to plain text mode 

    ... which worked fine at inputs. Lost now.


    Added after 19 minutes:


    Qt Code:
    1. element.evaluateJavaScript("this.selectedIndex = 2");
    To copy to clipboard, switch view to plain text mode 

    that works
    Last edited by GreyHound; 29th April 2011 at 23:56.

Similar Threads

  1. QtWebKit access HTML manipulated by javascript
    By rbp in forum Qt Programming
    Replies: 1
    Last Post: 19th September 2009, 02:29
  2. get html tag by clicking (webkit)
    By billconan in forum Qt Programming
    Replies: 0
    Last Post: 23rd June 2009, 22:07
  3. WebKit - accessing javascript results + googleMap
    By giusepped in forum Qt Programming
    Replies: 10
    Last Post: 30th May 2009, 00:01
  4. add custom HTML attribute by javascript in QtWebKit
    By sand.fj.wen in forum Qt Programming
    Replies: 3
    Last Post: 17th April 2009, 07:25
  5. Qt 4.4 WebKit: WYSIWYG HTML editor?
    By 24pm in forum Qt Programming
    Replies: 6
    Last Post: 13th March 2009, 10:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.