Button to Set Field Value (JS)

  • 3 August 2016
  • 5 replies
  • 270 views

Badge +7

Hi All,

I am very new to JS.

I want a series of buttons, when one of them is clicked, it will write a certain value to a text field hidden on my form.

I have given my single line text box a JS ID, called "TabRules".

On button1, I have set client click to "Tab1Function()"

Now I need help writing that function!

I tried this but no luck:

function Tab1Function () {

NWF$("Tab1").click();

document.getElementById("TabRules").value = "My value";

}


5 replies

Badge +8

Hello Dave Georgopoulis​ you're close! Here's a few updates to your scripts that should get you working!

Custom JavaScript in Form Settings:

function Tab1Function () {

  NWF$('#' + TabRules).val("My value");

}

JavaScript within your custom button's Client Click property:

NWF$(document).ready(function(){

    Tab1Function();

});

A few Notes:

  • Since you're already calling the Tab1Function() within your button's client click property, this doesn't need to be a part of the function itself (removed this piece).
  • I also did a little clean-up inside your function and used a jQuery approach to assigning your new "my value."

Good luck!

Badge +7

Wow! Thank you so much Patrick!

I can't believe I was "close" but I appreciate the encouragement!

The writing to the field is working perfectly!

Now I just have to figure out why rules won't fire!

thanks again happy.png

Badge +8

No problem Dave Georgopoulis​ – happy to help!

Badge +4

How can we do the same to set a value on a SQL request control. which is rendered as Label.

Badge +1

Hi Patrick,

I am wanting to do the same action with replacing a value, but I want to take a people picker field and set it to nothing. Is there a way to do this that you know of?

Reply