SitePoint Sponsor

User Tag List

Page 6 of 8 FirstFirst ... 2345678 LastLast
Results 126 to 150 of 184
  1. #126
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    Thank for the hint that is solved. But if you notice the first row "End" column is showing me value between 0 and -1. I have tried like to update the start value $(this).val = min; but is not working either too.
    The -1 is from it getting the next start value and removing 1 from it.
    That's well and good when the next start value has a positive number in it, but you don't want to do that when it has 0, right?

    That indicates that you only want to calculate the end max from the next start value when that next start value is more than 0

    So, start the max value at a suitable default:

    Code javascript:
    var max = $(form).data('end_max');

    Find out what the next start value is:

    Code javascript:
    var nextStartValue = Number(nextStartField(this).val());

    Then decide if you need to bring the max value lower:

    Code javascript:
    if (nextStartValue > 0) {
        max = nextStartValue - 1;
    }
    Last edited by paul_wilkins; Apr 7, 2011 at 00:31.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  2. #127
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I have set it like this Number.MAX_VALUE = 200; another thing I have tried like this to update the the startValue $(this).val = min; But unfortunately both is not working either.

  3. #128
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    I have set it like this Number.MAX_VALUE = 200;
    Yo have just learned that it is a read-only property.

    If you want to set a limit like that, then set is as data on the form.

    Code javascript:
    $(form).data('end_max', 200);

    And read it when required as:

    Code javascript:
    var max = $(form).data('end_max');

    Quote Originally Posted by newtomysql View Post
    another thing I have tried like this to update the the startValue $(this).val = min;
    Go look at the jQuery val() documentation page. You will see that you're using it incorrectly to set a value on a jQuery object.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #129
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I have updated my pages. Can you have a look I think the method to retrieve the max value have some problem. Sometimes it shows NaN.

  5. #130
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    I have updated my pages. Can you have a look I think the method to retrieve the max value have some problem. Sometimes it shows NaN.
    That happens when no max value is assigned to the validation.

    Look at your code, and you will see where you have commented out a vital line that assigns a value to a variable called max.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #131
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I have commented it and put at the top this line var max = Number(nextStartField(this).val()) - 1 || $(form).data('end_max');. But I still got problem with the NaN.

  7. #132
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    I have commented it and put at the top this line var max = Number(nextStartField(this).val()) - 1 || $(form).data('end_max');. But I still got problem with the NaN.
    Whatever happened to the solution from post #126?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #133
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Done accordingly but still the NaN is appearing. What else must I change ya?

  9. #134
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I have check the problem is that $(form).data('end_max'); give NaN/undefined. I have put the alert to check on for it debugging person.

  10. #135
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    I have check the problem is that $(form).data('end_max'); give NaN/undefined.
    That means that the value hasn't actually been set.

    Look at where you set the value for 'end_max' and you will find the problem. Does the form variable exist when you set the value? If not, you may need to move that statement to a different location.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  11. #136
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Ok I have put in the function below it works. Why it does not work just below the document ready statement?
    function setupStartAndEndRules(form)
    {
    $(form).data('end_max', 200);

  12. #137
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    Ok I have put in the function below it works. Why it does not work just below the document ready statement?
    Because just below the ready statement, the script has no idea of what the form variable is supposed to be.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  13. #138
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I am wondering can I control the "Add" such way that if the "End" column is not fill it will not allow to add a new row. The problem I notice is that say I have row "Start" is 15 and "End" is empty. Then I press "Add" a new row with "Start" as 1 is created and this will mess everyting else.

  14. #139
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    I am wondering can I control the "Add" such way that if the "End" column is not fill it will not allow to add a new row.
    So you want to return out of the add function if there are any empty end fields?

    You can check for any end fields that are empty, and if there are any, just return back out.

    Code javascript:
    if ($('input[name^="end"]:empty').length > 0) {
        return false;
    }

    You could also use a live onchange event on the end fields to enable/disable the add button itself.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  15. #140
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I have added it at the add function but it does not allow me to add further rows. Even though the row have been filled.

  16. #141
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Okay then, it seems that :empty only checks the attribute of the field instead of its actual value, so let's ensure that the right thing is being checked for.

    Code javascript:
    var endFields = $('input[name^="end"]');
    var isEmpty = function () {
        return this.value === '';
    }
    if (endFields).filter(isEmpty).length === 0) {
        return false;
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  17. #142
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    First there was a "(" missing here if (endFields).filter(isEmpty).length === 0) then I have added but now the problem when the end is empty it allows to add further but when is fill does not allow is the opposite of what we want.

  18. #143
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    First there was a "(" missing here if (endFields).filter(isEmpty).length === 0) then I have added but now the problem when the end is empty it allows to add further but when is fill does not allow is the opposite of what we want.
    That's one of the odd things that can occur when throwing out code on the fly.

    This should work:

    Code javascript:
    var endFields = $('input[name^="end"]');
    var isEmpty = function () {
        return this.value === '';
    }
    if ((endFields).filter(isEmpty).length > 0) {
        return false;
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  19. #144
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Ok it works now. The problem now I have include this dynamic grid with some other form elements. http://183.78.169.54/v3/addOnceSetup.php. If you notice I have change this line $(form).find("table.dynatable tbody").append(prot);. The problem is now it creates two rows when I press the add button. Secondly all my other elements like reset button ,combo boxes all have alignment problem. How can I solve this ?

  20. #145
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    I'm finding that nothing happens at all when selecting Add after putting in an end number on Chome. IE does two instead.

    Why don't you try using a context selector instead:
    Code javascript:
    $("table.dynatable tbody", form).append(prot);
    Last edited by paul_wilkins; Apr 10, 2011 at 16:59.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  21. #146
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Yes I have tried but it gives me this error Object does not support this property or method. Any solution to this?

  22. #147
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    Yes I have tried but it gives me this error Object does not support this property or method. Any solution to this?
    Place the $ sign in front? I'll update the previous post to show that.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  23. #148
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I have updated my codes but is the same still. Can you see what else is wrong ? Is it because I have this dynamic table stored in a bigger table outside there?

  24. #149
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Dear Paul,
    I have updated my codes but is the same still. Can you see what else is wrong ? Is it because I have this dynamic table stored in a bigger table outside there?
    No, it's because of where you put your form.

    Currently your form is outside of the TD element. That's illegal, and web browsers do different crazy undefined things due to that.

    Code:
    <tr>
        <form ...>
        <td>
            ...
        </td>
        </form>
    </tr>
    Move the form inside the TD element, and don't forget to do the same with the </form> tag.


    Code:
    <tr>
        <td>
            <form ...>
                ...
            </form>
        </td>
    </tr>
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  25. #150
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    874
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Updated accordingly but still the same problem.


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
  •