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

    JS - HTML error

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 170 Views 3 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.
    • Chris FullmerC Offline
      Chris Fullmer
      last edited by

      This line of code keeps poppingup js script errors in my webdialog:

      t = %Q^<input type="submit" id="113" value="332" onclick="change_time('#{id.to_s}')" />^

      Specifically its the onclick that does it. If I remove that, then I get no errors. The error I get is a Expected: ';' error. The js function being called looks like this

      function change_time(scene_id){ alert(scene_id); }

      So, is there some obvious js syntax issue here? Thanks in advance.

      EDIT: My string that I said is giving me problems is a ruby string that I send in to my webdialog depending on events in SketchUp.

      Lately you've been tan, suspicious for the winter.
      All my Plugins I've written

      1 Reply Last reply Reply Quote 0
      • Chris FullmerC Offline
        Chris Fullmer
        last edited by

        In case it matters, this is the puts statement of what that code simplifies out as, just to see that my id.to_s is gettiny inserted right:

        <input type="submit" id="113" value="332" onclick="change_time('tl00001')" />

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

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

          <input type="submit" id="113" value="332" onclick="change_time('tl00001');" /> ❓

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

          1 Reply Last reply Reply Quote 0
          • Chris FullmerC Offline
            Chris Fullmer
            last edited by

            Yeah, I tried that and it doesn't help either.

            I've also tried removing the the #{variable} and just replacing it with a plain text string in ruby. And it still causes errors. But removing it and not sending in an argument to the function works juist fine and the elrt box pops up with "undefined". So it seems to work great until I try to pass in an argument.

            Oh well. How could I pass the id of the element that the onclick is part of? These buttons are all part of special <div id="tl_001"> and each id is unique. So how would I write my onclick to do like this:

            onclick="time_change(this.id);"

            hmm, is that it? this.id? That was a guess of what I would like the syntax to be. Is it something like that just to pass the id into the js function?

            Thanks,

            Chris

            ps the js-html interaction is ridiculous and tedious and I hate it.

            Lately you've been tan, suspicious for the winter.
            All my Plugins I've written

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

              yes this.id would pass the object's id, '113' in the example above.

              [id property](http://msdn.microsoft.com/en-us/library/ms533880(v)

              [this (reserved words)](http://msdn.microsoft.com/en-us/library/0779sbks(v)

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • Chris FullmerC Offline
                Chris Fullmer
                last edited by

                Excellent, thanks Dan. It is working as expected, but I'm still very confused what the error was. This code works:

                id = "113" t = %Q^<form><input type="button" value="Click me!" id="#{id}" onclick="change_time(this.id)" /></form>^

                But this one causes errors:

                id = "113" t = %Q^<form><input type="button" value="Click me!" onclick="change_time('#{id}')" /></form>^

                As I've been playing with it over and over, it seems everytime I introduce the single quote into the function arguments, it crashes. But I'm doing it that was in other very similar onclick functions.

                Oh well, its beyond me. Thanks for helping everyone, I've got a wokring version now!

                Chris

                Lately you've been tan, suspicious for the winter.
                All my Plugins I've written

                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