What is JotForm?
JotForm is a free online form builder which helps you create online forms without writing a single line of code. No sign-up required.
At JotForm, we want to make sure that you’re getting the online form builder help that you need. Our friendly customer support team is available 24/7.
We believe that if one user has a question, there could be more users who may have the same question. This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern.
Using a custom JS script to handle a large number of rules on a condition?Asked by markashton on October 03, 2014 at 12:22 PM
Is there a limit on the number of rules one can set on a condition?
Is there an interface issue with regard to adding many rules to a condition ... like will it run out of space ;-?
I will require, for a single form, one condition with 1500 rules ...
The condition is to update a form field value ... I will have to add 1500 of these rules ... because I have 1500 names (there will be a couple of other conditions too but with only a few rules) ... is there a better way of doing this with conditions??
Though my answer would normally be "Unlimited" for most users, you are not most users. I'll go ahead and pass this along to our dev's to see if there is indeed a hard cap or any performance loss issues with adding this many. As manually testing this would take a substantial amount of time for both you and me to do, I would rather ask before proceeding.
If you need different values output to another field based on 1500 different names, I believe the way you are going about it may be the only solution.
We heard back from our developer, and as you may expect the idea of 1500 rules gave him pause for concern. 1500 of any sort of conditional check in JS would likely hog a lot of resources and cause the system to freeze.Our response is no, we don't support 1500 rules, but don't have a fixed upper limit implemented. Our dev requested more time to evaluate that and will provide an update if a clear answer can be provided.
- build the form in JF, without the conditions.
- download the full source code
- add a custom JS script that conducts the checks/field updates that you'd like.
I'm under the impression you're a coder, but if you'd like assistance with that we frequently help out with these sorts of scripts.
That seems like a great suggestion - the JS script route.
I'm not actually a 'hard' coder but I am a website developer.
With regard to the JS script would you be most kind as to just give me a pointer in terms of its content. I'd be most grateful.
Essentially, each name updates a couple of fields with text.
If you could give me a lead on that I'll pay your mortgage for a month ;-)
The idea for it would be to grab the ID of the Full name field and match it against the values array.
Lets say for now, as an example that the ID of this box is "fullname" and that the field that you want to update has an id of 'resultfield'.
var agents = ["Hannah Watts","Hajar Alafifi","...."];
var v = $("#fullname").val(); //we can use .text() as well..
Now we just need to match it against the array and that can be done like so:
if($.inArray(v, agents) != -1)
//It is in the array
$("#resultfield").text() = 'CMI'
Once your jotform is creates however we can take a closer look and provide you with the exact code. I should mention that the above code was not tested out as I wrote it as an example, although it should work.
Do let us know if you have any further questions.
A simple jotform with everything required is this:
The Full name is actually an Autocomplete field
Depending on the Full name added ... the other two fields are then filled accordingly ... as you well know from your example above.
So, my requirement is simple ... to prefill the two fields based on the name ... of course the 1500 names is the problem so I am very grateful you advised of this solution.
A working proof of concept would be fantastic ... using the two names you have used ... I'll be in your debt ;-)
Many Thanks for your valued help.
Give us a couple days to put this together. We should have a proof of concept by the end of the week at the latest. As you note, this is the right way to solve the issue since manually entering 1500 names through our form would be quite tedious.
That would be fantastic. I
Many Thnaks Mark
It's been a super hectic week, but wanted to get a demo out to you. This only updates one field and it's always to the value 'CMI'. What I imagine you want are a series of lists of names, each of which maps to different values for the other fields. Once this is integrated in your system, that should be easy to update.
Here's how to see the working demo:
- download the full source code of the form. I used a clone of your form:
Instructions on downloading full source code: http://www.jotform.com/help/104-How-to-get-the-Full-Source-Code-of-your-Form
- directly above the closing body tag < / body >, place this code:
That should work if embedding the code in a standalone html page. If you're using a CMS, such as wordPress, there are other considerations. More info on that can be found here:
Also, one task that can be done with a simple script is converting a long list of names into comma separated values. Please take a look at this POC, and if we get to the point of needing the 1500 list of CSV names, we can assist with that.
Thanks for all your effort. I greatly appreciate it.
Unfortunately, I can't make it work ... but as all the code necessary is in the hosted html file it should be easy to work out what the problem is.
What did I do?
I cloned your form
I copied the full source code ... created an html document here:
Am I miossing something? The autocomplete works nicely ... but no desired pre-fill/update field function.
Hope you can help.
I looked at this and looks like it only works properly in FireFox. It doesn't work immediately in Chrome. I will look into that and figure out what's going on.
Apologies for the bug in the first response. For anyone who's curious, I believe this was the cause. It's related to the autocomplete function not working well with the change event.
Please replace the bottom script with this version.
Note that this version makes the field update after the user clicks away from the name field, as opposed to after the name field has changed but the user is still focused on it. Here's a demo that works for me across FF/Chrome/Safari/IE8/IE10:
Let me know what you think.