Javascript link to a form field

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

sudjain
Ebase User
Posts: 8
Joined: Fri Jul 24, 2009 4:02 am

Javascript link to a form field

#1

Postby sudjain » Tue May 25, 2010 2:21 pm

I want to invoke the javascript function 'onclick' if the form field say textarea is clicked.Please help me on the same.
0 x

Hovik
Moderator
Moderator
Posts: 184
Joined: Tue Sep 11, 2007 8:58 am

#2

Postby Hovik » Wed May 26, 2010 4:20 pm

Here are the steps required to achieve this:

1. Add the following to HTML++ of your form:

Code: Select all

<script language=javascript>
function setuservar3&#40; fieldValue1&#41; &#123;
  for &#40;i=0; i<document.RW.elements.length; i++&#41; &#123;
      if &#40;document.RW.elements&#91;i&#93;.name == '$USERVAR3'&#41; &#123;
         document.RW.elements&#91;i&#93;.value = fieldValue1;
         break;
      &#125;
   &#125;
&#125;
function externalSubmit &#40;&#41; &#123;
      if &#40;validate&#40;&#41;&#41; &#123;
         document.RW.nextPageFlag.value=1;
         document.RW.submit&#40;&#41;;
      &#125;
&#125;
</script>
2. Define the Textarea field as a label field and add something like this as it's label (adjust rows and cols to suit your requirements):

Code: Select all

<tr>
<td valign='top' class='ufsflDEFAULT' width='51%' colspan='1'><label>Comments</label>
</td>
<td valign='top' colspan='2' class='ufsfeDEFAULT ufsfgb2DEFAULT'><span class='ufsfeffDEFAULT'><textarea rows="3" cols="30" class='ufsfeffDEFAULT' onclick="setuservar3&#40;'XYZ'&#41;;  externalSubmit&#40;&#41;;" ></textarea></span>
</td>
</tr>
Note that onclick must issue an externalSubmit() for the form to know of the click.

3. If you wish the form to detect a click in the above field, add a control field to the bottom of the page, then add the following fpl to its validation event.

Code: Select all

if &#91;$USERVAR3 = 'XYZ'&#93;
	set $USERVAR3 = '';  // clear it for the next time
	message 'User clicked in the Text Area field';
endif
I hope this helps.

Hovik Avedian
Ebase Support
0 x

sudjain
Ebase User
Posts: 8
Joined: Fri Jul 24, 2009 4:02 am

#3

Postby sudjain » Wed May 26, 2010 5:11 pm

I can detect the onclick event with the mentioned steps, however if there is any mandatory field before this text area , javascript popup comes up 'say this filed must be entered' when i click the textarea.
Is there any way so that this mandatory field checks are not invoked when i click the field?
Also i am not able to invoke the control field fpl.I have created a field and changed its property to 'Control Field' then i have pasted the below fpl in the script and added to the validation event of the field.Is this the right way?
0 x


Who is online

Users browsing this forum: No registered users and 116 guests