markW - Tuesday, January 30, 2007 5:04 PM:
How do I add a button to a form, with an OnClick event that runs a method?RobMcAveney - Tuesday, January 30, 2007 5:15 PM:
Hi markW -
Welcome to the forum. On your form, create a field of type "Button", then select the field and go to the "Field Event" tab. Create a new field event, choose the method you wish to run, and set the event to "onClick". Save the form, and the next time you open it the button should work.
Hope that helps -
Rob
storl - Friday, May 27, 2016 10:08 AM:
Hi,
I have a form linked to the TOC, so it will show when I click the menu item in the TOC. I have added some HTML elements on this form (so not of type button). Should I be able to add OnClick field events to these elements? (I can't get it to work at the moment)
Thanks in advance.
Best regards,
Lisa
RobMcAveney - Wednesday, June 8, 2016 10:47 AM:
I believe the OnClick field event was only intended for buttons. Inside HTML elements you can use standard DOM events to run code (e.g. <h1 onclick="alert('here')">Heading</h1>)
storl - Thursday, June 9, 2016 2:49 AM:
Ok. Does this mean that I can't reuse a method, that I would need to copy the method code in each html block?
storl - Thursday, June 9, 2016 4:20 AM:
Hi,
An additional question. Now I have used a different approach. I did use the button type. I have styled the button using an OnLoad form event. This is working fine, the only thing is, that the standard hover style is now disabled. Do you know how I can make it happen that the button gets a different color on hover?
Thanks in advance.
Best regards
Yoann Maingon - Saturday, June 11, 2016 11:19 AM:
Hi Lisa,
no you don't have to copy the method.
if you want everything in the same file add your javascript within <script></script> tags at the end of your html page.
You can have a method like this:
function sayhi(){
alert("Hi");
}
in this case your html tag would look like : <button onclick="sayhi()"/>
Yoann Maingon - Saturday, June 11, 2016 11:27 AM:
Hi Lisa,
Not sure what you are trying to achieve but you can try this :
<button id="b1" onmouseout="selectDefaultState()" onmouseover="selectOverState()"></button>
<script>
function selectOverState(){
document.getElementById("b1").style.color = "blue";
}
function selectDefaultState(){
document.getElementById("b1").style.color = "";
}
</script>
I haven't tried it.
storl - Monday, June 13, 2016 2:34 AM:
Hi Yoann,
Thanks for your reply. Where should I create this code? When I have a field of type Button, the HTML inputfield disappears.
What I am trying to achieve: create buttons in company style. So, define shape and color, with the color changing when hovering over the button. With the onload event, I have been able to define the shape and color (and I can use the normal OnClick field event on the form). Only the hovering is a problem now.
Yoann Maingon - Monday, June 13, 2016 3:15 AM:
Ok, in this case use CSS instead
in your html page add the following
<style>
#buttonID{
background-color: #00F;
}
#buttonID:hover{
background-color: #0F0;
}
</style>
And please also set the button shape using CSS.
General advice, don't try to much to style your application on a per-item basis. Use general CSS rules. Aras provides a default css file which you can reuse to standardize the way your application looks. But you are also welcome to use standard CSS libraries like bootstrap to use it on specific pages.