JS - HTML error
-
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 thisfunction 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.
-
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')" />
-
<input type="submit" id="113" value="332" onclick="change_time('tl00001');" />
-
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.
-
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)
-
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
Advertisement