SitePoint Sponsor

User Tag List

Page 5 of 13 FirstFirst 123456789 ... LastLast
Results 101 to 125 of 310
  1. #101
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    You can add a validation rule to each of those fields, using a required dependency-callback rule that checks if the other select is different. If it's not different, it fails the validation.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  2. #102
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    How to solve on the earlier problem where if the first value selected which is empty of the second column and I want that to apply on the 4th column too.

  3. #103
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    How to solve on the earlier problem where if the first value selected which is empty of the second column and I want that to apply on the 4th column too.
    Ensure that the one on the 4th column has a matching empty option.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #104
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    But now both value is '' so is that considered mathed?

  5. #105
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    But now both value is '' so is that considered mathed?
    What ever mathed is considered to be, I could not comment.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #106
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    About the dependency callback. If I do like this is not sufficient right. I do now how to link one locationFrom to another locationTo to make sure their values are different for row 2 onwards till before the last row.

    $("#form1").validate( {
    rules: {
    locationFrom:
    {
    required: true;
    },
    locationTo:
    {
    required: true;
    }

    }

    });

  7. #107
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    About the dependency callback. If I do like this is not sufficient right.
    That's right. Those there are required properties that are being set. You won't find any help from those, or from required dependency-expressions. You need to use required dependency-callbacks (see the link above) to achieve what you want with those extra requirements.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #108
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I know what you saying is that to check the value of locationFrom not equal locationTo as below but I dont know the exact syntax. Any hint on the syntax.

    $("#form1").validate( {
    rules: {
    locationFrom:
    {
    required: true;
    value : !valueLocationTo
    },
    locationTo:
    {
    required: true;
    value : !valueLocationFrom
    }

    }

    });

  9. #109
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    I know what you saying is that to check the value of locationFrom not equal locationTo as below but I dont know the exact syntax. Any hint on the syntax.
    Absolutely, the syntax is shown fully over at the required dependency-callback documentation page.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  10. #110
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Is it something on this line $("#locationFrom").val()!=$("#locationTo").val().Will this work?

  11. #111
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    Is it something on this line $("#locationFrom").val()!=$("#locationTo").val().Will this work?
    It seems that returning that from the required dependency-callback function should do the job.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  12. #112
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I am confuse is the code is snippets right ?

  13. #113
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    I am confuse is the code is snippets right ?
    It seems to be.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  14. #114
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I have done as below but unfortunately it is not showing any effect?

    $("#form1").validate({
    rules: {
    locationFrom:
    {
    required: true,
    value : $("#locationFrom").val()!=$("#locationTo").val()
    },
    locationTo:
    {
    required: true,
    value : $("#locationFrom").val()!=$("#locationTo").val()
    }
    }
    });

  15. #115
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    I have done as below but unfortunately it is not showing any effect?
    If you look at the documentation about the required dependency-callback you will see that it needs to be in a function, like this:

    Code javascript:
    required: function(element) {
        return $("#age").val() < 13;
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  16. #116
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I modified it to be like this but still not validation done. Can you tell me where I am wrong?

    $(document).ready(function() {

    $("#form1").validate({
    rules: {
    locationFrom:
    {
    required: function(element)
    {
    return $$("#locationFrom").val()!=$("#locationTo").val();
    }

    },
    locationTo:
    {
    required: function(element)
    {
    return $$("#locationTo").val()!=$("#locationFrom").val();
    }
    }

    }

    });

  17. #117
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Those double dollars don't look right for a start.
    The element that's passed to the function, that's the field that's being validated so you can replace the first selector with $(element).val() instead

    Is the second selector in each function a valid one? Perhaps you should use a relative selector instead, such as:
    $('select', $(element).parent().next().next());
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  18. #118
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Can you see if this is correct?

    $("#form1").validate({
    rules: {
    locationFrom:
    {
    required: function(element)
    {
    return $(element).val()!=$("#locationTo").val();
    }
    },
    locationTo:
    {
    required: function(element)
    {
    return $(element).val()!=$('select', $(element).parent().next().next());
    }
    }
    }
    });

  19. #119
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    Can you see if this is correct?
    Can you please provide a link to your test page?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  20. #120
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Here is the link http://183.78.169.54/v3/addRoute.php. Thank you.

  21. #121
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    Here is the link http://183.78.169.54/v3/addRoute.php. Thank you.
    Currently you are using $('#locationTo') when no element exists with that identifier. Secondly, well look at this rule:

    Code:
    locationFrom: {
        required: function(element) {
            ...
        }
    },
    You have no element on the page with a name of locationFrom, so the validator just won't be able to apply that rule.

    You should not need unique identifiers for the form elements. Instead, once the form elements have unique names, you should be able to refer to those form elements by their form name, from which you can then traverse the DOM to the other field that you want to compare it with.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  22. #122
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    How to cater for my locationTo[] and locationFrom[] ? Do you mean that I should run a loop and check on each row if the column 2 and column 4 is the same?

    Quote Originally Posted by paul_wilkins View Post
    Currently you are using $('#locationTo') when no element exists with that identifier. Secondly, well look at this rule:

    Code:
    locationFrom: {
        required: function(element) {
            ...
        }
    },
    You have no element on the page with a name of locationFrom, so the validator just won't be able to apply that rule.

    You should not need unique identifiers for the form elements. Instead, once the form elements have unique names, you should be able to refer to those form elements by their form name, from which you can then traverse the DOM to the other field that you want to compare it with.

  23. #123
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    How to cater for my locationTo[] and locationFrom[] ? Do you mean that I should run a loop and check on each row if the column 2 and column 4 is the same?
    The rule you create needs to have the same name as the form element that the rule applies to.

    Whenever you add a new row, you need to add new rules that relate to that new row. And likewise when you remove a row. You'll need to remove any rules that no longer apply to that row.

    That's why traversing the DOM is so very useful, because you're then not stuck with other rules being as badly affected when you add/remove rows.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  24. #124
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I am not too use but I have tried something like this can you comment. I call it assign rules.

    $("table.dynatable button.add").click(function() {
    var form = this.form;
    id++;

    // Get a new row based on the prototype row
    //var prot = master.find(".prototype").clone();
    var prot = $(form).data('prototype').clone();
    prot.find('[name^="id"]').attr("value", id);
    prot.find('[name^="locationFrom"]').attr('name', 'locationFrom[' + id + ']');
    prot.find('[name^="locationFrom"]').attr('id', 'locationFrom[' + id + ']');
    prot.find('[name^="locationFrom"]').attr('value', '');
    prot.find('[name^="eventFrom"]').attr('name', 'eventFrom[' + id + ']');
    prot.find('[name^="eventFrom"]').attr('value', '');
    prot.find('[name^="locationTo"]').attr('name', 'locationTo[' + id + ']');
    prot.find('[name^="locationTo"]').attr('value', '');
    prot.find('[name^="eventTo"]').attr('name', 'eventTo[' + id + ']');
    prot.find('[name^="eventTo"]').attr('value', '');

    //var dropLocationFromName = 'locationFrom[' + id + ']';
    //alert("dropLocationFromName : "+dropLocationFromName);
    //$(form).find("dynamicRow").append(prot);
    $("#dynamicRow").find('tbody').append(prot);
    //$("#form1").validate();
    //$('#' + dropLocationFromName).rules('add', {required: true});
    assignRules(form);
    return false;
    });


    function assignRules(form)
    {

    $('td:nth-child(2) select',form).each(function ()
    {
    $(this).rules('add', {required:

    function(element) {
    return $(element).val()!=$("#locationTo").val();

    );

    }
    }

  25. #125
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    I have difficulty seeing how that assign rules function will work, considering that you require the location in the first and last rows to be the same, but different in the inbetween rows.

    Also, what happens when someone removes a row? Shouldn't the rule for that removed row also then be removed? Other fields in the table also need to be updated when a row is removed. If it's the last row that's removed, the new bottom row needs to be validated for matching locations.

    It seems that the most appropriate technique to use is to update the appropriate row rules whenever a row addition or a row removal occurs.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •