LiveValidation only for an option of a select

monak83 21 Jan, 2015
Hi,
I have a form where a select has some options: only for one options I would validate a field.
on my html file I have:
SELECT -> name="tipo_nolavorazioni"
OPTION -> 80 (from select name="tipo_nolavorazioni")
FIELD -> name="base"

on js file I have assigna variable like here:
var tipo1 = form.elements['tipo_nolavorazioni'].value;



- if TIPO1 = 80 I would validate field BASE < 250;
- if TIPO1 != 80 I would any validation

My problem is that the first time i load page all works good and when I select TIPO1 = 80 live validation works fine.
But when I change TIPO1 to a value different from 80 (TIPO1 != 80) live validation remains and I can't process my form.

I have add a remove function but dosent' works.

Here my code:
window.addEvent('domready', function(){
  var valid = new LiveValidation('text_2', {insertAfterWhatNode : "errore_base"});
  if (tipo1==80) { valid.add(Validate.Numericality, { maximum: 250, tooHighMessage: "Max 250cm" }); };
  if (tipo1!=80)  { valid.remove(Validate.Numericality, { maximum: 250, tooHighMessage: "Max 250cm" }); valid.destroy(); };
  });


here my forms (now I have comment code that validate my forms because I'm on a live site)
http://www.sgagrafica.com/stampa-banner-striscioni.html
monak83 22 Jan, 2015
thanks for your time but your reply is OT!!!
Any ideas?
GreyHead 23 Jan, 2015
Hi monak83,

it looks as though your JavaScript only runs when the page is loaded. You presumably need it to run when the option selected changes?

Bob
monak83 23 Jan, 2015
Hi Bob,
thanks so much for your repli.
Can you make an example?
monak83 26 Jan, 2015
Hi Bob,
I have seen but seems that my live validation is under function onchange and so it should be called every time i change a value in my select.
Where I'm wrong?
Max_admin 27 Jan, 2015
Hi Monak,

As Bob already suggested, you need to set your code to run when the select changes, just wrap the 3 lines inside into a select element change event.


$('select').addEvent('change',function(event) {
    //??
});


Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
monak83 28 Jan, 2015
Hi Max,
I have added this cod at the bottom of my .js file...but dosen't works.
I have added out of my function updatethis(form) called with onchange.
Where i'm wrong?
http://www.sgagrafica.com/stampa-banner-striscioni.html

window.addEvent('domready', function(){
	 $('select_5').addEvent('change',function(event) {
		var valid = new LiveValidation('text_2', {insertAfterWhatNode : "errore_base"});
		if (tipo1==80) { valid.add(Validate.Numericality, { maximum: 250, tooHighMessage: "Max 250cm" }); };
		if (tipo1!=80)  { valid.remove(Validate.Numericality, { maximum: 250, tooHighMessage: "Max 250cm" }); valid.destroy(); };
	 });
	});
GreyHead 28 Jan, 2015
I monak83,

It's a few years since ChronoForms used LiveValidation and I'm not longer very familiar with it. The script you posted doesn't seem to have any onChange event?

Bob
monak83 28 Jan, 2015
Hi Bob,
on my webpage you can see this:
<select class="cf_inputbox" id="select_5" size="1" title="Effettua una scelta!"  name="tipo_nolavorazioni" 
onkeyup="validateNumber()" onclick="validateNumber()" onChange="updatethis(this.form);">

http://www.sgagrafica.com/stampa-banner-striscioni.html
Max_admin 02 Feb, 2015
The onChange event calls a function named "updatethis", but the code you had should be triggered when any change is done to the field, assuming the page doesn't have any JS errors.

Where do you have your JS code placed ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Max_admin 03 Feb, 2015
Hi Monak,

I'm not sure, please try again the code I posted, maybe with a new form field, just make sure the field id matches the one in the code, and check if it works, it may need some debugging before you can get it to work!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
monak83 04 Feb, 2015
Chronoforms add some code like FORM tag so I don't know how debgging this. Do you think is a chronoforms bug or a bug on my JS file?
I can't solve this problem...I hope that experts like you will helpe me!!!
Thanks for your time
This topic is locked and no more replies can be posted.