JavaScript function variables in Html Custom Event Handlers

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

User avatar
Jez
Ebase User
Posts: 31
Joined: Thu Aug 21, 2008 11:03 am
Location: Hampshire County Council

JavaScript function variables in Html Custom Event Handlers

#1

Postby Jez » Wed May 27, 2015 3:11 pm

I'm trying to call a JavaScript function using the on-click Event, on the Html tab of the Custom Event Handlers option, for a ebase field.

The test function takes an input parameter. If I hard code this in the call, it works perfectly, but I need the parameters to be dynamic, based on the value of another ebase field.

I was hoping the following call syntax would work, using the old && notation to substitute an ebase field value at run-time:

F_JSFuncTest('&&P_PARAM_IN')

However, it doesn't :( instead it passes in the text &&P_PARAM_IN instead of the value of that field. I've tried this with and without the quotes as well as with double and single quotes:

F_JSFuncTest(&&P_PARAM_IN)
F_JSFuncTest("&&P_PARAM_IN")

Anyone have any ideas where I'm going wrong, or is it simply not possible?

Many thanks for any thoughts.
0 x
--------------------------------------
Jez Hollinshead - Hampshire CC

Segi
Ebase User
Posts: 649
Joined: Mon Dec 09, 2013 6:37 pm

#2

Postby Segi » Wed May 27, 2015 8:50 pm

Try this instead

F_JSFuncTest(fields.P_PARAM_IN.value);
0 x

User avatar
Jez
Ebase User
Posts: 31
Joined: Thu Aug 21, 2008 11:03 am
Location: Hampshire County Council

#3

Postby Jez » Thu May 28, 2015 8:19 am

Thanks Segi, good suggestion but it's not worked unfortunately :(
0 x
--------------------------------------
Jez Hollinshead - Hampshire CC

Segi
Ebase User
Posts: 649
Joined: Mon Dec 09, 2013 6:37 pm

#4

Postby Segi » Thu May 28, 2015 8:31 am

Please explain what error you are getting.

What is the value of the fields ? Did you print them out to the console ?
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#5

Postby Jon » Thu May 28, 2015 8:46 am

From client-side Javascript, you can ask the server for the value of the field e.g.

Code: Select all

var parmvalue = $eb.getFieldValue("P_PARAM_IN");
If the field is on the same page and the user can change it's value (i.e. the server might have an old value), you need a different approach.
0 x

User avatar
Jez
Ebase User
Posts: 31
Joined: Thu Aug 21, 2008 11:03 am
Location: Hampshire County Council

#6

Postby Jez » Thu May 28, 2015 8:48 am

Hi, so I have a very simple test JS function as follows:

Code: Select all

function F_JSFuncTest (txtText) {
  alert(txtText);
}
If I use the following HTML Custome Event Handler on the onclick Event of my Text field (<SPAN>), it works (i.e. I get an alert message with the 'Hello Worl' text I'm passing in):

Code: Select all

F_JSFuncTest &#40;'Hello World'&#41;
If I try to make the parameter dynamic, using any of the following (inc. your suggestion), I get nothing at all - completely dead onclick:

Code: Select all

F_JSFuncTest &#40;fields.P_PARAM_IN.value&#41;
F_JSFuncTest &#40;'&&P_PARAM_IN'&#41;
F_JSFuncTest &#40;&&P_PARAM_IN&#41;
I've made sure I've got some text (Hello World) in the P_PARAM_IN field.

Looking in the View Source option for the field within ebase, I can see that ebase is replacing the && with the following in the source:

Code: Select all

onclick="F_JSFuncTest &#40;&amp;&amp;P_PARAM_IN&#41;;
I think this is the problem - I need the actual && in the source and not &amp;&amp;
0 x
--------------------------------------
Jez Hollinshead - Hampshire CC

User avatar
Jez
Ebase User
Posts: 31
Joined: Thu Aug 21, 2008 11:03 am
Location: Hampshire County Council

#7

Postby Jez » Thu May 28, 2015 8:54 am

Thanks Jon, sorry crossed posts so missed your reply before my last post!

Yes, I had thought of trying to approach the problem that way - passing the field name in, then grabbing the value of the field from within JS rather than trying to actually pass the value in direct. Wouldn't have known the code syntax though, so thank you very much for that :D

Thanks all,
0 x
--------------------------------------
Jez Hollinshead - Hampshire CC

Segi
Ebase User
Posts: 649
Joined: Mon Dec 09, 2013 6:37 pm

#8

Postby Segi » Thu May 28, 2015 9:04 am

I didnt realize you were talking about from the client side but Jon is right. You also have to set the field to be read only in the field properties for client callable in order to be able to read it from the client side
0 x

kotinkarwak
Ebase User
Posts: 109
Joined: Mon Sep 21, 2015 9:55 pm

#9

Postby kotinkarwak » Tue Sep 29, 2015 2:16 pm

Continuing this discussion.

A return value of undefined if the field is not "read only" under the fields property of "Client Accessibility".

How would I temporarily change the fields status in order to grab its content and return that data in the alert message as per this query? Please also show how to put it back.


UPDATE:
Saw this which clarifies the issue.
http://forum.ebasetech.com/forum/viewto ... ight=alert
0 x


Who is online

Users browsing this forum: Bing [Bot] and 11 guests