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

Question

Question

How to check a box once a user fills out a field or attaches a document to a form?

asked on March 30, 2015

I would like to use JavaScript to check a box once a user fills out a single line field or when they attach a document to the form.

Can this be done and how?

0 0

Answer

SELECTED ANSWER
replied on April 8, 2015

So this seems to work for test fields, but hasn't been overly tested.

I can't get it to work for adding files but found a link on Code Project with some advice....

http://stackoverflow.com/questions/12973889/jquery-event-on-dynamic-table-row-change

http://api.jquery.com/change/

 

In the example below, remove the "alert" line. It's just there for testing.

 

1 0

Replies

replied on March 31, 2015 Show version history

Hi Mason,

This is something best Googled for but here is one method using JQuery to wait for a change to a text field.

$('#q49 input').change(function(){
    $('.myCheckBox input').attr('checked',true);
    }
);

In the code sample above, I've used two different styles of selectors (#q49 is an ID and .myCheckBox is a Class), just to demonstrate the options, given I don't know which style you prefer!.

-Ben

 

 

1 0
replied on March 31, 2015

Thank you Ben! I will try this out. I will let you know what I find. Does Laserfiche have any answer? 

0 0
replied on March 31, 2015 Show version history

Hey Mason,

 

I tested Ben's script and once you add the document ready bit at the top of the script, it works great!  One thing that I noticed is that the script works well for checkbox fields where there's only 1 checkbox or if you want to check ALL the checkboxes within that field.  

 

If you'd like to limit the automated action to only check ONE box in the field, you can identify the specific checkbox by using this line:

$('#Field2-0').attr('checked',true);

This is replacing the line in Ben's script:

$('.myCheckBox input').attr('checked',true);

 

#Field2-0 refers to the the checkbox field on my form and the first checkbox within that field.

#Field2-1 refers to the the checkbox field on my form and the second checkbox within that field.

 

Let me know if you have any questions!  And thanks to Ben for sharing the script!

2 0
replied on April 1, 2015

Rob,

What I am looking to do is if the user attaches a document, the box would get checked letting the Approver know that this section has been completed. 

What would be the conditional statement for when a user attaches a document, the box gets checked. 

0 0
replied on April 1, 2015

Hey Mason,

 

The change function should work for this field as well.  When I changed ('#q1 input').change(function(){ to ('#q3 input').change(function(){ , it worked fine for me.  Of course, in this case, q1 was my single line field and q3 is my file upload field.

0 0
replied on April 7, 2015 Show version history

I am having issues with this for when I use a file upload. 

I tested it by using an alert and it is not passing through. 

I am using the same script as above.

0 0
replied on April 7, 2015

Did you remember to include the document ready function?

 

$( document ).ready(function() {
});

What version of Forms are you running?

 

If you did include the document ready function, you can feel free to include a screenshot of your CSS and Javascript page, so long as it doesn't contain any sensitive info.  If you don't feel comfortable sharing your screen on this public forum, you can always send an email to Presales@Laserfiche.com and reply to this post to let me know that you've included a file for my review.

0 0
replied on April 7, 2015 Show version history

I think it may be because they are both in a table. 

See screenshot. 

 

2015-04-07 14_03_52-192.168.100.164 - Remote Desktop Connection.png
0 0
replied on April 7, 2015

Do those fields need to stay in a table?  That likely will change some of the specific identifiers within the script to find the correct element to modify with the Javascript.

0 0
replied on April 7, 2015

Yes, they do. I have the form formatted at 964 width and it makes the single line item fields look off centered. 

I would prefer to use a table. 

0 0
replied on April 8, 2015

I am going to use CSS to change the label width of a single item field. 

Then run the code that you provided. 

Thank you Ben.

0 0
replied on April 10, 2015

No worries :)

0 0
replied on April 10, 2015

I  have one more question for you guys. I apologize for this again.

I am able to now populate the checkbox from the signature. 

However, I am needing to store the data for the boxes that are checked in a sql table.

I have been able to fill in the value of the single line item field when the box is checked.

However, I am needing to now know how to populate a checkbox when single line item field is populated by a lookup rule. The problem I have is that when the document loads it immediately run a lookup and checks the box when the field is empty. I am not sure how to get around this.

 

Do you guys have any other ideas? Let me know if I should open another answers forum? 

My code is below.

//#q530 is the file upload
//#q567 is the single line item
//var b = 100; 

$('#q530 input').change(function(){
  $('#Field529-1').attr('checked',true);
    $('#q567 input').val(b);
});

 $('#q567 input').change(function() {
   
   if($('#q567 input').length > 0)
  {
 
   $('#Field529-1').attr('checked',true);
  }

});

 

0 0
replied on April 10, 2015 Show version history

Hi Mason,

This has been addressed by others for other similar issues. Essentially, there is no way to check when a lookup has been completed. You can use the .change event to determine when a look up has begun then use the timeout() function to wait an arbitrary amount of time. The lookup should have competed after 2000 milliseconds, for example.

Or you can poll rapidly to determine when there are no more values to be returned. 

-Ben

 

 

0 0
replied on April 10, 2015

I  have one more question for you guys. I apologize for this again.

I am able to now populate the checkbox from the signature. 

However, I am needing to store the data for the boxes that are checked in a sql table.

I have been able to fill in the value of the single line item field when the box is checked.

However, I am needing to now know how to populate a checkbox when single line item field is populated by a lookup rule. The problem I have is that when the document loads it immediately run a lookup and checks the box when the field is empty. I am not sure how to get around this.

 

Do you guys have any other ideas? Let me know if I should open another answers forum? 

My code is below.

//#q530 is the file upload
//#q567 is the single line item
//var b = 100; 

$('#q530 input').change(function(){
  $('#Field529-1').attr('checked',true);
    $('#q567 input').val(b);
});

 $('#q567 input').change(function() {
   
   if($('#q567 input').length > 0)
  {
 
   $('#Field529-1').attr('checked',true);
  }

});

 

0 0
replied on April 10, 2015

I  have one more question for you guys. I apologize for this again.

I am able to now populate the checkbox from the signature. 

However, I am needing to store the data for the boxes that are checked in a sql table.

I have been able to fill in the value of the single line item field when the box is checked.

However, I am needing to now know how to populate a checkbox when single line item field is populated by a lookup rule. The problem I have is that when the document loads it immediately run a lookup and checks the box when the field is empty. I am not sure how to get around this.

 

Do you guys have any other ideas? Let me know if I should open another answers forum? 

My code is below.

//#q530 is the file upload
//#q567 is the single line item
//var b = 100; 

$('#q530 input').change(function(){
  $('#Field529-1').attr('checked',true);
    $('#q567 input').val(b);
});

 $('#q567 input').change(function() {
   
   if($('#q567 input').length > 0)
  {
 
   $('#Field529-1').attr('checked',true);
  }

});

 

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

Sign in to reply to this post.