SitePoint Sponsor

User Tag List

Page 12 of 13 FirstFirst ... 28910111213 LastLast
Results 276 to 300 of 310
  1. #276
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Below is how I plan to do it? Can you comment?
    I don't think that what you're doing there is going to work.

    If you use the added row as a reference, you can then set some change events on the dropdown fields of interest.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  2. #277
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Need your help in some codes there I dont get to do your idea?

  3. #278
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Need your help in some codes there I dont get to do your idea?
    Let's simplify this then. The prot variable is a jQuery reference to the row that was just added. You can use that row as the context of a jQuery selector, which will allow you to select one of the form fields. You can then use change() to assign a function to be invoked when that select field changes.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #279
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I dont know if I got this correct.

    $(prot.change( function() {
    var otherField = $('select[name^="locationTo"]', closest('tr').prev('tr'));
    otherField.val(this.value);
    });

  5. #280
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by newtomysql View Post
    I dont know if I got this correct.
    There's this part that hasn't been done yet:
    You can use that row as the context of a jQuery selector, which will allow you to select one of the form fields.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #281
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    How to do that part? Isnt the prot is representing the new row?

  7. #282
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by newtomysql View Post
    How to do that part? Isnt the prot is representing the new row?
    jQuery allows you to use a context selector from within which the selection takes place. The row would be the context in this situation, from which you select the appropriate drop-down form field.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #283
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Ok I tried to put the prot as context. When must I put the $ and not ?
    $('select[name^="locationFrom"]', prot).change( function() {
    var otherField = $('select[name^="locationTo"]', closest('tr').prev('tr'));
    otherField.val(this.value);
    });

  9. #284
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by newtomysql View Post
    When must I put the $ and not ?
    Can you please provide more information about what you're puzzled by?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  10. #285
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,

    1. IS below changes correct?
    $('select[name^="locationFrom"]', prot).change( function() {
    var otherField = $('select[name^="locationTo"]', closest('tr').prev('tr'));
    otherField.val(this.value);
    });
    2. When do we use $ and when not to use it?

  11. #286
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by newtomysql View Post
    1. IS below changes correct?
    It seems to be. Testing it though is a better way to tell.

    2. When do we use $ and when not to use it?
    $ is used to give you access to jQuery methods. If an object is already a jQuery object then there is no need to use the dollar symbol with that object.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  12. #287
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Can visit this link http://183.78.169.54/v3/addRoute.php? In the begining there is 2 rows by default all works fine the rule for first and last row. Then immedialely I add a new row the new row is the last row rite but the rules does not work for it now and even the new rules as below is not working.

    $('select[name^="locationFrom"]', prot).change( function() {
    var otherField = $('select[name^="locationTo"]', closest('tr').prev('tr'));
    otherField.val(this.value);
    });

  13. #288
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Can visit this link http://183.78.169.54/v3/addRoute.php? In the begining there is 2 rows by default all works fine the rule for first and last row. Then immedialely I add a new row the new row is the last row rite but the rules does not work for it now and even the new rules as below is not working.
    Previous conversation gave the impression that new rows were going to be added before the last row. Are new rows always going to be added as the very last row? Because if so, you will need to modify the rules for the select fields of what used to be the last row.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  14. #289
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    You said it will be very complex to add before the last row a lot of indexing need to be changed rite which I am not sure how to do it unless your help me on those stufff? Please help me on how to modify it I am kind of too much confuse with these stuff?

  15. #290
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Please help me on how to modify it I am kind of too much confuse with these stuff?
    That's why we break things down in to smaller and simpler pieces, until it can be expressed in a programming language.

    Which part would you like help with at the moment?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  16. #291
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Ok before we get there which is a better method to keep adding a row before the last row or after the last row? So based on your best suggestion then you help me modify the codes. Thank you.

  17. #292
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Ok before we get there which is a better method to keep adding a row before the last row or after the last row? So based on your best suggestion then you help me modify the codes.
    What is the more likely usage by people using it? Will they enter in the information for the start and finish of their journey, then add in sections inbetween, or will they more likely enter the information in a sequential manner from start to finish?

    Which method will be of more use to the people who will end up using the system?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  18. #293
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    They will enter sequentially and then only come to the last part.

  19. #294
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by newtomysql View Post
    They will enter sequentially and then only come to the last part.
    In that case the event on the last row will need to behave differently when it's not the last row.

    So that you don't need to tell the script to remove an old event and to then set up a new event on what used to be the last row, you can make the code in the event a bit smarter, so depending on whether the row is the first or last row, or something else inbetween, different behaviour occurs.

    Or as psuedo-code for one of the events, the locationFrom for example:

    Code:
    if first-or-last-row
        set locationTo on same row to the locationFrom value
    
    if not first-row
        set locationTo on previous row to the locationFrom value
    The code that the locationTo change event runs would be similar, except that instead of checking that it's not the first row, it would check that it's not the last row before setting the next locationFrom instead.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  20. #295
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    How combine then into one as of the || application. The problem I understand your pseudo but the problem I am really lost in how to do it via jquery.


    $('table.dynatable tbody tr:first select[name^="locationFrom"]').change( function() {
    var otherField = $('select[name^="locationTo"]', $(this).parents('tr'));
    otherField.val(this.value);
    });

    $('table.dynatable tbody tr:first select[name^="locationTo"]').change( function() {
    var otherField = $('select[name^="locationFrom"]', $(this).parents('tr'));
    otherField.val(this.value);
    });

    $('table.dynatable tbody tr:last select[name^="locationFrom"]').change( function() {
    var otherField = $('select[name^="locationTo"]', $(this).parents('tr'));
    otherField.val(this.value);
    });

    $('table.dynatable tbody tr:last select[name^="locationTo"]').change( function() {
    var otherField = $('select[name^="locationFrom"]', $(this).parents('tr'));
    otherField.val(this.value);
    });

    $('select[name^="locationFrom"]', prot).change( function() {
    var otherField = $('select[name^="locationTo"]', closest('tr').prev('tr'));
    otherField.val(this.value);
    });

  21. #296
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by newtomysql View Post
    How combine then into one as of the || application. The problem I understand your pseudo but the problem I am really lost in how to do it via jquery.
    First group the locationFrom ones together. Then create one function that will be assigned to all of those locationFrom events, perhaps called handleLocationToUpdate. That one function can be put together using the pseudo-code structure.

    That one function can then be assigned to handle the change event of each of the locationFrom fields.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  22. #297
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    So where and who will call the handleLocationToUpdate? I have commented every thing and now I have this. Please comment and I dont know how to make it to be for both first and last row?

    function handleLocationToUpdate()
    {
    $('table.dynatable tbody tr select[name^="locationFrom"]').change( function() {
    var otherField = $('select[name^="locationTo"]', $(this).parents('tr'));
    otherField.val(this.value);
    });
    }

  23. #298
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by newtomysql View Post
    So where and who will call the handleLocationToUpdate?
    Whereas before you assigned an anonymous function to the change event, you can give only the name of a function to the change event instead.

    Before:
    Code javascript:
    $('...').change( function() {
        ...
    });

    After:
    Code javascript:
    $('...').change(handleLocationToUpdate);
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  24. #299
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Should it be like this. So how in the handleLocationToUpdate I will refere back to the particular row to decide whether is first or last row or any other row then?


    $('table.dynatable tbody tr select[name^="locationFrom"]').change( handleLocationToUpdate);

    function handleLocationToUpdate()
    {


    }

  25. #300
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Ok I have test it read it calls the alert only for the first two rows not for the rest row when I do a change in the locationFrom drop down list?

    $('table.dynatable tbody tr select[name^="locationFrom"]').change( handleLocationToUpdate);

    function handleLocationToUpdate()
    {
    alert("TEst");

    }


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
  •