sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Get_element value for checkbox

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 4 Posters 804 Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Q Offline
      Qverburg
      last edited by

      Hi all,

      Im trying to get the state of a checkbox from a webdialog, but it seems that ruby thinks the checkbox is always on.

      Here is some simple test code:

      test.rb

      def testing @@testwindow = UI::WebDialog.new("test", false, "test", 200, 200, 200, 200, true) html_path = Sketchup.find_support_file "test.htm" ,"Plugins" @@testwindow.set_file(html_path) @@testwindow.show end

      test.htm

      <html> <body text="FFFFFF"> <input type="checkbox" id="test" checked > </body> </html>

      now when you run testing in sketchup, and the window shows up, try:
      @@testwindow.get_element_value("test")
      now turn the checkbox off and try it again.

      What am i missing here?

      Kind regards,
      Quintus Verburg

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        what is the value it returns?

        I'm not quite sure, but...
        checkbox values are a bit quirky crossbrowsers - might need some help of a javascript to determine the state and return a corresponding value.

        But knowing the return value you get from .get_element_value will help.

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • Q Offline
          Qverburg
          last edited by

          @@testwindow.get_element_value("test") on @@testwindow.get_element_value("test") on

          first one is with checkbox checked, second one without ckeckbox checked......

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            This page might be of use: http://www.quirksmode.org/js/forms.html#scheckbox
            I do have a suspicion that checkboxes doesn't report a value that reflect the checked state. So you might want to make a JS function that reads the checked state of the checkbox and put it into a hidden input field.

            so you first call that JS script using .execute_script - giving the JS function the element id as argument. then read the value of the hidden input field.

            Thomas Thomassen β€” SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • Q Offline
              Qverburg
              last edited by

              Great idea!
              Thanks for your helpfull and quick responses πŸ˜„

              1 Reply Last reply Reply Quote 0
              • P Offline
                Pout
                last edited by

                or maybe like this

                1. ruby
                command = "_getcheckboxvalue()"
                webdialog.execute_script(command)
                
                1. javascript
                function _getcheckboxvalue(){
                //get the checkboxvalue
                thevalue=document.getElementById('test').value;
                //send it back to ruby
                query = 'skp;_sendcheckboxvalue@'+thevalue;
                window.location.href = query;
                }
                

                3.ruby

                webdialog.add_action_callback("_sendcheckboxvalue") {|webdialog,p|
                //p=the checkbox value
                //do something
                }
                

                (untested)

                1 Reply Last reply Reply Quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  The reason why I didn't use .add_action_callback calling back from JS to Ruby is that the amount of data might be limited and there are OSX issues with JS to Ruby callbacks.

                  Thomas Thomassen β€” SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply Reply Quote 0
                  • Q Offline
                    Qverburg
                    last edited by

                    Hmm this is strange.

                    When I try to get the checkbox value in the javascript, it's again always on.
                    The hidden textbox method also doesn't work because I can't seem to set the textbox value. (and if I could, the checkbox would say its always on....)

                    Any ideas?

                    1 Reply Last reply Reply Quote 0
                    • thomthomT Offline
                      thomthom
                      last edited by

                      In regard to the checkbox value - did you read my link?

                      Thomas Thomassen β€” SketchUp Monkey & Coding addict
                      List of my plugins and link to the CookieWare fund

                      1 Reply Last reply Reply Quote 0
                      • Q Offline
                        Qverburg
                        last edited by

                        @thomthom said:

                        In regard to the checkbox value - did you read my link?

                        Yes I did thank you for that. Played with it for 2 hours but couldn't manage to read the checkbox values in that manner.
                        The only thing that worked was the getElementById but it still reports the checkbox as on when its not.

                        1 Reply Last reply Reply Quote 0
                        • Dan RathbunD Offline
                          Dan Rathbun
                          last edited by

                          You might just try and keep the state of the control in your own Js variable, and then use onclick or onchange events to toggle the variable ON/OFF value.

                          I do it for 'toggle buttons' such as buttons that collapse / uncollapse a <DIV>.

                          I'm not here much anymore.

                          1 Reply Last reply Reply Quote 0
                          • 1 / 1
                          • First post
                            Last post
                          Buy SketchPlus
                          Buy SUbD
                          Buy WrapR
                          Buy eBook
                          Buy Modelur
                          Buy Vertex Tools
                          Buy SketchCuisine
                          Buy FormFonts

                          Advertisement