Javascript to call button inside a table records list

Javascript to call button inside a table records list

  


Hi, i'm currently trying to call an invisible button, through the use of the "onchange" javascript function.

I've done it all as if the button was outside a table records...the onchange="document.all.wtButtonName.click()" line is there, but the name doesn't change through the lines...

Do you have any idea of how can I get the button of a current table list records to click?

Thank you,

Best regards
You would need to use something like this: this.parentNode.parentNode.getElementsByTagName('input')[0].click()
To click on the first input element in the row this event was triggered.
Cheers,
Tiago Simões
Hi Diogo,

Tiago's answer should get you there, but just so that you know there is an alternative way to do what you want. If you fill the Name property of your button (i.e. MyButton), which I think you already did, the button runtime Id will become available as a property on the Expression Editor. Meaning you can reference it in any Expression you write.

In fact, you should try not to hardwire your Id's in javascript and instead use this technique. This will allow you to seamlessly change names without breaking any client-side code.

So, just to make it clear, the steps you should take are:
1 - Create the table records (TableRecords1) and create one button in one column making it invisible.
2 - Fill the name property for that button
3 - On your onchange event, use "javascript : document.getElementById('"+Mybutton.Id+"').click();"
4 - Inside the action triggered by your button, you can use TableRecords1.Current to access the record associated to that specific line (you don't really need to pass Id's...)

One extra tip. Avoid using document.all as this is not standards compliant and will break on some browsers.

Get back to me if you need extra help!

Gonçalo
Well, that sure did solve the problem :-).

I actually used something like :

onpropertychange="RefreshTotals(this);"

_____Webscreen Javascript______

function RefreshTotals(obj){ this.parentNode.getElementsByTagName('input')[2].click();
}


Since the button was on the same paragraph as the checkbox, i used only "this.parentNode" which represents the current paragraph.


Thank you,

Best Regards,

Diogo Cordeiro
Hi Diogo,

Nice that you got your problem solved.

Just check your RefreshTotals function, as you use this.parentNode instead of obj.parentNode (the parameter). You're probably referencing the document object or something like that...

Also, be advised that this code will break when you change the layout of your page or add a new input to your table records (placed before your current one).

I hope these points will help you get a quality and built-to-change solution :)
Cheers,
Gonçalo Gaiolas
One more thing.

Apparently onpropertychange is not a cross-browser event, so your code won't work in browsers other than IE.

I don't know if this is a requirement for you or not, but wouldn't it be better to use onchange which is standard?
Cheers,
Gonçalo
Thank you Gonçalo.... I actually only saw your post after replying to Tiago...

Anyway, i changed to get the button id and it works just fine :-).

I think i'll use the onclick event then, because the onchange isn't that great when working with several checkboxes....

(oh, and about last post, i wrote the code wright, just posted it wrong, sorry.)

Best regards,

Diogo