Hey all,
I'm struggling with, what i think to be, a fairly simple problem.
I have a text field and i want to make sure that the user doesn't input a number below 500 or above 2000, but i just can't get the validation to work. I've tried various approaches and ways of doing it, from reading around on google and the forums. But none of them seem to work for me.
What is the easiest way of achieving this validation?
I'm struggling with, what i think to be, a fairly simple problem.
I have a text field and i want to make sure that the user doesn't input a number below 500 or above 2000, but i just can't get the validation to work. I've tried various approaches and ways of doing it, from reading around on google and the forums. But none of them seem to work for me.
What is the easiest way of achieving this validation?
Hi Meisner,
In the element settings Validation tab scroll down to the Custom function box and add validateMinMax
In the Setup Tab drag a Load JavaScript action into the On Load event and drag it up before the HTML (Render form) action. Add this JavaScript to it:
Save and test.
Bob
[[>> later : edited to fix typo in event <<]
In the element settings Validation tab scroll down to the Custom function box and add validateMinMax
In the Setup Tab drag a Load JavaScript action into the On Load event and drag it up before the HTML (Render form) action. Add this JavaScript to it:
function validateMinMax(el) {
return ( el.val() >= 500 && el.val() <= 2000 ) ;
}
Save and test.
Bob
[[>> later : edited to fix typo in event <<]
Hey GreyHead,
Thank you for your quick reply!
I've tried adding the code you mentioned, but without luck. Something got me wondering though, you mentioned the HTML (Render form) action in the Submit event. I don't have this action in my submit event, is that needed? My thought is that it just displays/renders the form after hitting submit, which i don't really need.
I've attached a screenshot of my setup page for reference
Thank you for your quick reply!
I've tried adding the code you mentioned, but without luck. Something got me wondering though, you mentioned the HTML (Render form) action in the Submit event. I don't have this action in my submit event, is that needed? My thought is that it just displays/renders the form after hitting submit, which i don't really need.
I've attached a screenshot of my setup page for reference
I forgot to add that with the code added, the form just submits with no objection even if i input a number outside the 500-2000 range.
HI Meisner,
Apologies - must be Monday morning :-( The Load JavaScript action needs to go in the On Load event.
Bob
Apologies - must be Monday morning :-( The Load JavaScript action needs to go in the On Load event.
Bob
I was -so- close to just doing that, cause of your mention of the html render, but ending up going "Nah, he's a pro, just do what he says"😀
That works like a charm, thanks! Can i add a custom validation popup, as it right now just says something along the lines of "Please check one of the fields/options". Could i add a bit of code to the JS to make it go "Amount has to be between 500 and 2000" instead.
That works like a charm, thanks! Can i add a custom validation popup, as it right now just says something along the lines of "Please check one of the fields/options". Could i add a bit of code to the JS to make it go "Amount has to be between 500 and 2000" instead.
Hi Meisner,
Add it to the title attribute of the input element - that will over-ride the default message.
Bob
Add it to the title attribute of the input element - that will over-ride the default message.
Bob
This topic is locked and no more replies can be posted.
