Adding javascript onclick event to field

Post any questions regarding Installing or Upgrading Ebase, including problems starting up the Ebase Xi Server or Designer

Moderators: Jon, Steve, Ian, Dave

Vircos
Ebase User
Posts: 97
Joined: Thu Sep 13, 2007 6:07 am
Location: The Netherlands

Adding javascript onclick event to field

#1

Postby Vircos » Wed Nov 10, 2010 9:00 am

Is it possible to add an javascript onclick event to a field?
0 x
What's the meaning of Justice...

AJDulk
Ebase User
Posts: 94
Joined: Fri Sep 14, 2007 12:18 pm
Location: The Netherlands
Contact:

Re: Adding javascript onclick event to field

#2

Postby AJDulk » Wed Nov 10, 2010 1:59 pm

Sure.
0 x

Vircos
Ebase User
Posts: 97
Joined: Thu Sep 13, 2007 6:07 am
Location: The Netherlands

Re: Adding javascript onclick event to field

#3

Postby Vircos » Wed Nov 10, 2010 2:39 pm

AJDulk wrote:Sure.
Mmm, you people of Rotterdam are very short with answers :shock: . I also should have asked how hahaha :lol:

So, how am I able to do that?
0 x
What's the meaning of Justice...

AJDulk
Ebase User
Posts: 94
Joined: Fri Sep 14, 2007 12:18 pm
Location: The Netherlands
Contact:

Re: Adding javascript onclick event to field

#4

Postby AJDulk » Fri Nov 26, 2010 1:37 pm

Sorry for not getting back to you earlier. The easiest way is to use an Event Listener. In the HTML++ you place a reference to your JavaScript that includes the code that parses the code looking for the field and adds the watch on the onClick event.

Depending on what browsers you are looking to support you may have bubbling issues - that is where the order in which things are processed and whether or not the processing stops may be an issue.

For an Ebase centric solution I would need to dive into the Ebase documentation and see what they have (sometimes it surprises me what has been added since I first started using Ebase).
0 x

Vircos
Ebase User
Posts: 97
Joined: Thu Sep 13, 2007 6:07 am
Location: The Netherlands

Re: Adding javascript onclick event to field

#5

Postby Vircos » Mon Dec 06, 2010 2:38 pm

AJDulk wrote:Sorry for not getting back to you earlier. The easiest way is to use an Event Listener. In the HTML++ you place a reference to your JavaScript that includes the code that parses the code looking for the field and adds the watch on the onClick event.
I have done that already.
AJDulk wrote: Depending on what browsers you are looking to support you may have bubbling issues - that is where the order in which things are processed and whether or not the processing stops may be an issue.
And that's the problem which I ran into.

AJDulk wrote: For an Ebase centric solution I would need to dive into the Ebase documentation and see what they have (sometimes it surprises me what has been added since I first started using Ebase).
I agree with you. However I did not find anything useable in the documentation this time.
0 x
What's the meaning of Justice...

Simon
Ebase User
Posts: 25
Joined: Thu Aug 27, 2009 9:43 am
Location: Hampshire County Council
Contact:

#6

Postby Simon » Tue Dec 07, 2010 11:11 am

Hi Vircos

We use the buildFieldArray() function that is supplied by Ebase to retrieve an array of all Ebase fields. You can then assign a function to the onclick event of each field:

Code: Select all

function assignOnClick()
{
  var countFieldArray = buildFieldArray();
  
  for&#40;var i = 0; i < countFieldArray.length; i++&#41;
  &#123;
    var thisName  = countFieldArray&#91;i&#93;.fieldName.replace&#40;'F&#58;','LF'&#41;;
    var thisField = document.getElementById&#40;thisName&#41;;
    thisField.onclick = onclickfuntion;	
  &#125;
&#125;
The above assigns the same function to all fields, but you could add some conditions in there to check for a specific field or field type, eg:

Code: Select all

if &#40;thisField && &#40;thisField.tagName == "TEXTAREA"&#41;&#41;
Hope this helps

Simon
0 x


Who is online

Users browsing this forum: No registered users and 51 guests