You are viewing limited content. For full access, please sign in.

Question

Question

Can I pass a reference to a Field to a function in Javascript?

asked on January 24, 2014 Show version history

I have a form with Radio buttons I want to fill based on a lookup. I figured, "What a wonderful application of Javascript this could be!" Well, I seem to be having trouble.

 

What I am wanting to do is take the value of the field, say Field13, and pass it 1 or more parameters that will be used to test/set the radio button. 

 

Basically, say, I have a radio button with the options, Yes or No. I have the field above it hidden using CSS but filled by the Lookup and then have Javascript check for that hidden field to change. If the user decides to change it after that, then it won't do any harm. 

 

The tricky part of this is I really enjoy well written code and i have these fields in a few places on the same form. I want this function in javascript to be dynamic for each and future usage.

 

I was figuring of using boolean values for the hidden fields and sending the parameter of the radio button field to change, but that does not work. As soon as I put quotes anywhere when calling the function in an event listener, it runs it on load. 

 

I was thinking, hey, maybe I can pass the field number and make a string of the field name using that for when I want to set the radio button. But so far no luck. I figured I should prove that I can reference a field properly, so I tried taking the value from the field that will be autofilled and set it to another temporary field to show that i was referencing things properly.

 

Can someone please help me? 

 

EDIT:

Some ideas about what I'd love to be able to pass and use when I call a function to select the radio button: (Each of the bullets is a different idea of the parameter sets I thought might be useful in combination of each other)

  • The radio field number/Radio field
  • The Radio Field, # of options
  • The Radio Field, lookup value for option 1, option 1 value, lookup value for option 2, option 2 value

 

Also, currently I removed the CSS that makes the fields hidden

0 0

Answer

SELECTED ANSWER
replied on January 24, 2014

I managed to figure this out on my own, let me explain and share:

 

First, I added some alerts to see if/when the function was being called when i expected it.

 

Then, I noticed that it ran on load of page, and this got me thinking. I did some research and found that the event needs to trigger an embedded function that will call the function I wanted. 

 

Now, my code looks like this:

$('#Field1').change( function(){SetRadio(2)});

This sends the function the field number for the radio button and it uses the current value as the test. Now I can accomplish my goal once I figure out the setting of a radio button command, which I hope will not be difficult.

0 0
replied on October 2, 2018

Do you have the full JavaScript that you used please? I have a request to build the same functionality in to a form too.

 

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.