Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: mailhandler script and validation

  1. #11
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,957
    Thanks
    43
    Thanked 3,195 Times in 3,157 Posts
    Blog Entries
    12

    Default

    I would try (assuming mixedlollybartypes is the class name of the label, and that the label contains the select, and that there's no other element with the class mixedlollybartypes):

    Code:
    mixedlollybartypes:$('.mixedlollybartypes').find('select').val().join(','),
    Or (to take account for the possibility that none might be selected):

    Code:
    mixedlollybartypes:(function(){var val = $('.mixedlollybartypes').find('select').val(); return val? val.join(',') : '';})(),
    Or (using the method in your post):

    Code:
    mixedlollybartypes:(function(){
    	var val = [];
    	$('.mixedlollybartypes').find(":selected").each(function(i, s){
    		val.push($(s).text());
    	});
    	return val.join(',');
    })(),
    Last edited by jscheuer1; 01-10-2014 at 02:21 PM. Reason: add third method
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  2. #12
    Join Date
    Nov 2007
    Posts
    60
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Default

    Hi John,

    I have one more question with this form...I added a confirm-email field and I am looking for a way so that regular expression can check if both fields entered match.

    currently, the first email field has this:
    rx:{
    ".email":{rx:/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i,target:'input'},
    the new variable is emailconf.... how can I have in the rx:{} section when the form gets validated, a condition if .email==.emailconf ???

    thanking you in advance

  3. #13
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,957
    Thanks
    43
    Thanked 3,195 Times in 3,157 Posts
    Blog Entries
    12

    Default

    I would not use regular expression for that. I would simply confirm that the second is identical (===) to the first. If not, throw an error.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #14
    Join Date
    Nov 2007
    Posts
    60
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Default

    Hi John,

    thanks for the guideline.

    I added the following in the form...
    // check if emails are the same
    $('.erroremail').hide();
    $('#email2').change(function() {
    var email1 = $('#email1').val();
    var email2 = $('#email2').val();
    if(email2 != '' ) {
    if(email1 == email2 ){
    $('.erroremail').fadeOut();
    }
    else{
    $('.erroremail').fadeIn();
    }
    }

    });
    the code works fine but i have a visual issue...the rest of the error messages slideUp or Down instead of fadeIn() i used above.

    when i used the slideUp() function, to hide the element, the form elements below the .erroremail message, flicker...like jump up...whereas error message with the other boxes, move fluently

    any idea what could be wrong?

  5. #15
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,957
    Thanks
    43
    Thanked 3,195 Times in 3,157 Posts
    Blog Entries
    12

    Default

    I would have to see the page to know what to do exactly. In general, there should be a container element that's positioned static, or perhaps even relative, that has enough width and height to contain the absolutely positioned message div which can then slide up or down within that without changing the surrounding layout. Often jQuery takes care of part or all of that though, it depends how it's setup.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #16
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,957
    Thanks
    43
    Thanked 3,195 Times in 3,157 Posts
    Blog Entries
    12

    Default

    I see that all the other error fields are class="error". Why is the confirmation email one different (erroremail)? Also, I cannot find rx from your previous post, where is that?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #17
    Join Date
    Nov 2007
    Posts
    60
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Default

    Hi John,

    from the link I gave you to see the form, you can see the formsbk.js file

    the rx:
    rx:{
    ".name":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'input'},
    ".email":{rx:/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i,target:'input'},
    ".telephone":{rx:/^\+?(\d[\d\-\+\(\) ]{5,}\d$)/,target:'input'},
    ".address":{rx:/.{5}/,target:'input'},
    ".suburb":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'input'},
    ".eventtype":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'input'},
    ".eventdate":{rx:/.{5}/,target:'input'},
    ".guests":{rx:/.{2}/,target:'input'},
    ".location":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'select'},
    ".surfacearea":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'select'},
    ".verification":{rx:/2/,target:'input'}
    },
    as for the class name....I couldn't have it as .error since that class is handled (shown or hidden) by the formsbk.js. And also, the error message gets its validation from rx...in the case I want to compare 2 fields, I am not using reg-exp but plain jquery function

    The .erroremail appears only if the email1 and email2 fields are not the same (onchange event of email2)

  8. #18
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,957
    Thanks
    43
    Thanked 3,195 Times in 3,157 Posts
    Blog Entries
    12

    Default

    Right, I figured that out. What I think we should do is get formsbk.js to handle this by editing the isValid function allowing it to use a function instead of an rx if so configured in the main rx object. I'm not certain exactly how that would work so back up everything you have now first. What I think would work is adding this (highlighted) to the rx object:

    Code:
    					rx:{
    						".name":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'input'},
    						".email":{rx:/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i,target:'input'},
    						".emailconf":{rx:function(v){return v===_.getValFromLabel($('.email',th));},target:'input'},
    						".telephone":{rx:/^\+?(\d[\d\-\+\(\) ]{5,}\d$)/,target:'input'},
    						".address":{rx:/.{5}/,target:'input'},
    						".suburb":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'input'},
    						".eventtype":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'input'},
    						".eventdate":{rx:/.{5}/,target:'input'},
    						".guests":{rx:/.{2}/,target:'input'},
    						".location":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'select'},
    						".surfacearea":{rx:/^[a-zA-Z'][a-zA-Z-' ]+[a-zA-Z']?$/,target:'select'},
    						".verification":{rx:/2/,target:'input'}
    					},
    And changing the isValid function to (additions highlighted, but just replace it with this):

    Code:
    					isValid:function(el){							
    						var ret=true
    						$.each(_.rx,function(k,d){
    							if(el.is(k))
    								if(typeof d.rx === 'function'){
    									ret=d.rx(el.find(d.target).val());
    								} else {
    									ret=d.rx.test(el.find(d.target).val());
    								}									
    						})
    						return ret							
    					},
    That would also mean removing:

    Code:
    	// check if emails are the same
        $('.erroremail').hide();
    	$('#email2').change(function() {
        	var email1 = $('#email1').val();
        	var email2 = $('#email2').val();
        	if(email2 != '' ) {
        		if(email1 == email2 ){
          			$('.erroremail').slideUp();
        		}
       	 		else{
          			$('.erroremail').slideDown();
        		}
        	}
    	});
    And changing the erroremail span's class to just error.

    That should do it.

    The browser cache may need to be cleared and/or the page refreshed to see changes.

    Let me know what happens. I just did this in a mock up and it worked.
    Last edited by jscheuer1; 01-17-2014 at 12:19 AM. Reason: code correction
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Foundas (01-17-2014)

  10. #19
    Join Date
    Nov 2007
    Posts
    60
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Default

    You are the best John...works perfectly now!!!!

    many thanks for all your support

Similar Threads

  1. W3C Validation of script
    By s.willett in forum Flash
    Replies: 1
    Last Post: 09-06-2010, 09:17 PM
  2. Looking for validation script
    By jscoder in forum Looking for such a script or service
    Replies: 2
    Last Post: 01-02-2007, 09:31 AM
  3. w3c validation script
    By neilkw in forum HTML
    Replies: 6
    Last Post: 08-02-2006, 02:14 PM
  4. validation script
    By toolman in forum Dynamic Drive scripts help
    Replies: 4
    Last Post: 03-12-2006, 10:35 PM
  5. Help with validation of script
    By christy in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 10-17-2004, 06:23 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •