SitePoint Sponsor

User Tag List

Page 10 of 13 FirstFirst ... 678910111213 LastLast
Results 226 to 250 of 310
  1. #226
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Below is my latest codes. What else is preventing can you hint me? Thank you.

    var rowName = $('[name^="locationFrom"]', row);
    var rule = {
    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();

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

  2. #227
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    Below is my latest codes. What else is preventing can you hint me? Thank you.
    Well, rowName really shouldn't be called that, because it's the select field instead.

    And also, look at the return statement. Currently you are returning a comparison with a <td> value, which is just wrong. Shouldn't you instead be comparing with locationToValue?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #228
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Are you saying I dont need this line $(rowName).rules('add', rule); or replace it with something else? About the 4th select value will this be fine $('select', $(element).parent().next().next().next().next());?

  4. #229
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    Are you saying I dont need this line $(rowName).rules('add', rule); or replace it with something else?
    I'm saying that the variable name of rowName is misleading, since it is not the name of a row that is assigned to that variable.

    Code:
    var rowName = $('[name^="locationFrom"]', row);
    Calling it instead something like locationFrom or even just using field for the variable name, would be much less misleading.

    Quote Originally Posted by newtomysql View Post
    About the 4th select value will this be fine $('select', $(element).parent().next().next().next().next());?
    That is still the <td> element that you're selecting there.

    Look at what is assigned to the variable called locationToValue. You already have the correct reference to the field there, so you can just compare with that instead.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #230
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Does the changes below makes sense.
    var locationFrom = $('[name^="locationFrom"]', row);
    var rule = {
    required: function(element) {
    var row="",locationToValue="";
    row = $(element).parents('tr');
    locationToValue=$('[name^="locationTo"]', row).attr('value');
    return $(element).val()==locationToValue;

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

  6. #231
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Does the changes below makes sense.
    Yes, that seems to be better
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #232
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Does the changes below makes sense.
    It does, but on taking a further look at the validation documentation, there seems to be a much better way, with the equalTo(other) validation method

    Code javascript:
    var targetId = $('[name^="locationTo"]', row).attr('name'),
        rule = {
        equalTo: '#" + targetId
    };
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #233
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Do you want me to just change to this method is it? Where is the location from value then?

    var targetId = $('[name^="locationTo"]', row).attr('name'),
    rule = { equalTo: '#" + targetId};

  9. #234
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Do you want me to just change to this method is it? Where is the location from value then?
    They are where they were earlier, in reference to the rule object.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  10. #235
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I am a bit confuse. So now my link is here http://183.78.169.54/v3/addRoute.php. So can you comment why is not function yet?

  11. #236
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    I am a bit confuse. So now my link is here http://183.78.169.54/v3/addRoute.php. So can you comment why is not function yet?
    Quite possibly because you haven't made use of this part yet:

    Code javascript:
    var targetId = $('[name^="locationTo"]', row).attr('name'),    
    rule = {
        equalTo: '#" + targetId
    };
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  12. #237
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Based on my current codes as below.

    var locationFrom = $('[name^="locationFrom"]', row);
    var rule = {
    required: function(element) {
    var row="",locationToValue="";
    row = $(element).parents('tr');
    locationToValue=$('[name^="locationTo"]', row).attr('value');
    return $(element).val()==locationToValue;

    How will your new codes will be implemented? Can you tell me where to put those new codes into the existing codes?

    var targetId = $('[name^="locationTo"]', row).attr('name'),
    rule = {
    equalTo: '#" + targetId
    };
    }
    };
    $(locationFrom).rules('add', rule);

  13. #238
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    How will your new codes will be implemented? Can you tell me where to put those new codes into the existing codes?
    You replace the rule variable with the new code.

    You might as well include a required definition with the new rule too:
    Code javascript:
    var targetId = $('[name^="locationTo"]', row).attr('name'), 
        rule = {
        required: true,
        equalTo: '#" + targetId
    };
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  14. #239
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I have done the changes can you visit the link http://183.78.169.54/v3/addRoute.php . The problem even though I make both the same value it is giving me error "Please enter the same value again."


    Quote Originally Posted by paul_wilkins View Post
    You replace the rule variable with the new code.

    You might as well include a required definition with the new rule too:
    Code javascript:
    var targetId = $('[name^="locationTo"]', row).attr('name'), 
        rule = {
        required: true,
        equalTo: '#" + targetId
    };

  15. #240
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Just to make sure that we're doing everything properly, we should use .attr('id') instead of .attr('name') for the targetId

    It's the target id that the equalTo method uses to get the field that you're comparing with.
    Since it's the target id being used, an id of "location[1]" is invalid and doesn't work, so you may have to use "location1" for the id, but "location[1]" for the name of the fields.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  16. #241
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I have done the changes as below. I am confuse with your second paragraph of your previous post. Must I make the locationFrom static is it?

    var locationFrom = $('[name^="locationFrom"]', row);
    var targetId = $('[name^="locationTo"]', row).attr('id');
    rule = {
    required: true,
    equalTo: '#' + targetId
    };
    $(locationFrom).rules('add', rule);
    }

  17. #242
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    I am confuse with your second paragraph of your previous post.
    Let's try and unconfuse things then. The form fields use an array index so that PHP is capable of retrieving them as an array on the server-side. The square brackets that are used in the name are not valid when used as an id.

    What that means is that "locationFrom[1]" is valid as a name, but not as a unique identifier. So if you are going to use a unique identifier (as must be done with the equalTo method) you must not use square brackets in the identifier. A useful way to achieve that is to use "locationFrom1" for the id instead, when the name is "locationFrom[1]"

    And that means, the id attributes in the HTML code for the form fields should be updated, as well as the code that sets the name/id on the added fields.
    Last edited by paul_wilkins; Jun 27, 2011 at 20:13.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  18. #243
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Actually why Jquery is not taking this as unique locationFrom[1] but insist on locationFrom1? I dont quite understand this part. So that means I have to change all the bracket method to just adding the Id beside the name is it?

  19. #244
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Actually why Jquery is not taking this as unique locationFrom[1] but insist on locationFrom1? I dont quite understand this part.
    The reason why is that name attributes accept a much larger range of characters within their name, than id attributes do.
    Name attributes allow any type of CDATA content, whereas id attributes allow only A TO Z, digits and decimals, hyphens, underscores, and colons.

    Recently in another thread I was writing about how names and ids differ, which you might find useful too.
    Quote Originally Posted by newtomysql View Post
    So that means I have to change all the bracket method to just adding the Id beside the name is it?
    The name attributes should retain the same bracket notation. It's only the id attributes that should change.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  20. #245
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    At last is working fine after the changes on ID. Ok my next problem is how to make sure for that the value of locationFrom on a new line is same the locationTo of the previous line?

  21. #246
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    At last is working fine after the changes on ID.
    That's great to hear. In looking over what we've done here in the past month, it would normally take a developer one hour to do on their own. So even though it seem like a long process, it's only due to the manner in which the learning is being provided here.

    Quote Originally Posted by newtomysql View Post
    Ok my next problem is how to make sure for that the value of locationFrom on a new line is same the locationTo of the previous line?
    The function that adds the new line can do that job. The this keyword in the function will refer to the add button, so you can gain a reference from that to the row itself. Then you can access the locationTo field in a similar manner as before, and use its value to set the new row's locationFrom field to an appropriate value.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  22. #247
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Yes it took a long while but never mind it was good learning though. I have one problem here. The problem on default I will have 2 rows ready. The problem is that the rows I am going to add suppose to be in between the 2 rows so how to implelement your new idea?

  23. #248
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    Yes it took a long while but never mind it was good learning though. I have one problem here. The problem on default I will have 2 rows ready. The problem is that the rows I am going to add suppose to be in between the 2 rows so how to implelement your new idea?
    If you had four rows, and were to add one, You could do it without duplication becoming a problem by first increasing the numbers of the last row. That would leave you with 1, 2, 3 and 5 for those rows, at which point the new row can be added.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  24. #249
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    So in the first case I have 2 rows rite. Then when I press add what should I do the to index in new row? Minus the index of the last row for the new row is it and add one new index to last row is it? So I have to update all the last row values is it? Is there any code snippet for this task ?

  25. #250
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    So in the first case I have 2 rows rite. Then when I press add what should I do the to index in new row? Minus the index of the last row for the new row is it and add one new index to last row is it? So I have to update all the last row values is it? Is there any code snippet for this task ?
    Nope, but you could create a function that does the job. It could set the index values of a row to whatever you require.

    It might be something like this:

    Code javascript:
    function setRowIndex(row, index) {
       ...
    }
    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
  •