SitePoint Sponsor

User Tag List

Page 8 of 13 FirstFirst ... 456789101112 ... LastLast
Results 176 to 200 of 310
  1. #176
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    How about the variable row which we use to assign name for the rule?
    Must we change to element too? I am confuse why some place is ok to use row?

  2. #177
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,676
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    How about the variable row which we use to assign name for the ule?
    Must we change to element too? I am confuse why some place is ok to use row?
    The row variable is only available within the context of the matchingFromAndTo function. It's not available from the dependency-callback function due to the validation plugin executing that function from a completely different execution context from the matchingFromAndTo function.

    In the dependency-callback function you have the element itself that is being validated, from which you can gain access to the other parts of the form that you need to check it against.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #178
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I am clear now. Another question why my alert show locationFrom without
    The row id in the bracket. Isn't the row variable show the exact row?

  4. #179
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,676
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    I am clear now. Another question why my alert show locationFrom without
    The row id in the bracket. Isn't the row variable show the exact row?
    You are correct in that it does show the exact name of the form field. Look at the HTML source code for your HTML form and you will see that the form fields have no row id in the bracket.

    The script that adds a row puts the row id in the added row, but the ones that the page starts off with don't have them. You may want to put them there in the HTML source of the form so that things then remain consistent.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #180
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Can you comment on the codes below.

    function matchingFromAndTo(row)
    {
    alert("ID : "+$('[name^="locationFrom"]', row).attr('name'));
    var rule = {};
    rule[$('[name^="locationFrom"]', row).attr('name')] =
    {
    required: function(element) {
    return $(element).val()==$(element).parents('tr').find("td").eq(4).val();;
    }
    }
    $(row).rules('add', rule);

    }

  6. #181
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,676
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Can you comment on the codes below.
    Does it work?
    If so, do you understand the code?
    If it's not easy to understand, what needs to be made clearer?

    Assuming that things get this far, you can create a variable called row in the function, so that a similar attribute starts with selector can be used as was used before.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #182
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Not is not working. I know I am just making some few mistake to get me there ready now will need your help definitely. I have done this $rowVariable = $(element).parents('tr'); and $locationToValue=$('[name^="locationTo"]', row).attr('value')]; . Can you comment?

    function matchingFromAndTo(row)
    {
    alert("ID : "+$('[name^="locationFrom"]', row).attr('name'));
    var rule = {};
    rule[$('[name^="locationFrom"]', row).attr('name')] =
    {
    required: function(element) {
    $rowVariable = $(element).parents('tr');
    $locationToValue=$('[name^="locationTo"]', row).attr('value')];
    return $(element).val()==$(element).parents('tr').find("td").eq(4).val();;
    }
    }
    $(row).rules('add', rule);

    }

  8. #183
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Have a look at the following line

    Code JavaScript:
    $locationToValue=$('[name^="locationTo"]', row).attr('value')];

    See the error? If you don't look towards the end where the semicolon is, you will notice you have a random square bracket. If you remove it your code should work normally again.

  9. #184
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear All,
    I have corrected it. But yet I still get the error is a undefined.

    function matchingFromAndTo(row)
    {
    alert("ID : "+$('[name^="locationFrom"]', row).attr('name'));
    var rule = {};
    rule[$('[name^="locationFrom"]', row).attr('name')] =
    {
    required: function(element) {
    $rowVariable = $(element).parents('tr');
    $locationToValue=$('[name^="locationTo"]', row).attr('value');
    return $(element).val()==$(element).parents('tr').find("td").eq(4).val();

    }
    }
    $(row).rules('add', rule);

    }

  10. #185
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,676
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    I have corrected it. But yet I still get the error is a undefined.
    The undefined error is the row variable inside of the dependency-callback function.

    In that function, declare a row variable and use something like $(element).parents('tr') to get that row.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  11. #186
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I have already done previously $rowVariable = $(element).parents('tr');
    as below is my function.

    function matchingFromAndTo(row)
    {
    alert("ID : "+$('[name^="locationFrom"]', row).attr('name'));
    var rule = {};
    rule[$('[name^="locationFrom"]', row).attr('name')] =
    {
    required: function(element) {
    $rowVariable = $(element).parents('tr');
    $locationToValue=$('[name^="locationTo"]', row).attr('value');
    return $(element).val()==$(element).parents('tr').find("td").eq(4).val();

    }
    }
    $(row).rules('add', rule);

    }

  12. #187
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,676
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    I have already done previously $rowVariable = $(element).parents('tr');
    as below is my function.
    Have you noticed that you are calling it rowVariable, but are trying to use it as row?

    Change rowVariable to row. It cannot clash with the other row variable that you have in the other function.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  13. #188
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Yes the reason I use different name worried of clash since you said is ok. Then I will use it as row. But even after changing the error is still there?

    function matchingFromAndTo(row)
    {
    alert("ID : "+$('[name^="locationFrom"]', row).attr('name'));
    var rule = {};
    rule[$('[name^="locationFrom"]', row).attr('name')] =
    {
    required: function(element) {
    $row = $(element).parents('tr');
    $locationToValue=$('[name^="locationTo"]', row).attr('value');
    return $(element).val()==$(element).parents('tr').find("td").eq(4).val();
    }
    }
    $(row).rules('add', rule);

    }

  14. #189
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Simply do this, remove the dollar sign "$" from the var and it should work fine.

  15. #190
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear SgtLegend,
    There is only one var that is var rule = {};? So which dollar sign you referring to?

  16. #191
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    In your code you have

    $row = $(element).parents('tr');

    Because the var name $row is not the same as

    $('[name^="locationTo"]', row).attr('value');

    the error is occurring, also var doesn't have to exist for a variable to be called a var.

  17. #192
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear SgtLegend,
    Which part are you referring about this "the error is occurring, also var doesn't have to exist for a variable to be called a var." The first part I have repaired.

  18. #193
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,676
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear SgtLegend,
    Which part are you referring about this "the error is occurring, also var doesn't have to exist for a variable to be called a var." The first part I have repaired.
    To clear things up, while it's not mandatory to declare variable using the var statement, but it's a good idea to do so anyway. Why? Because without it, the variable becomes a global variable. It's bad to rely on global variables because they can be easily clobbered by any other code using the same variable.

    Instead, use the var statement to declare the variable, so that the scope of that variable remains within the context of the function that you are using it in.

    Code javascript:
    var row = ...;
    var locationToValue = ...;

    Or as professionals prefer to do is, combine them in to one var statement.

    Code javascript:
    var row = ...,
        locationToValue = ...;
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  19. #194
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    After doing all the changes you suggested there is still error there. Below is my latest codes.

    function matchingFromAndTo(row)
    {
    alert("ID : "+$('[name^="locationFrom"]', row).attr('name'));
    var rule = {};
    rule[$('[name^="locationFrom"]', row).attr('name')] =
    {
    required: function(element) {
    var row="",locationToValue="";
    row = $(element).parents('tr');
    locationToValue=$('[name^="locationTo"]', row).attr('value');
    return $(element).val()==$(element).parents('tr').find("td").eq(4).val();

    }
    }
    $(row).rules('add', rule);

    }

  20. #195
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,676
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    After doing all the changes you suggested there is still error there. Below is my latest codes.
    Now that the other issue is sorted out, you can return a comparison between the element value and that locationToValue variable.

    Although, you may want to make the variable just locationTo, so that you can retrieve the value of each one at the same time when making the comparison.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  21. #196
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Will this be correct.

    locationToValue=$('[name^="locationTo"]', row).attr('value');
    return $(element).val()==locationToValue;

  22. #197
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,676
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Will this be correct.
    That seems like it should work.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  23. #198
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I still get the a undefined error.

  24. #199
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,676
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    I still get the a undefined error.
    When you say things like that without providing a way to progress further, it leaves us at a point where not much can be done.
    Please in the future provide a link to the page so that further progress can be made.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  25. #200
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Many apology sorry for the mistake here is the link http://183.78.169.54/v3/addRoute.php. Thank you.


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
  •