SitePoint Sponsor

User Tag List

Page 1 of 13 1234511 ... LastLast
Results 1 to 25 of 310
  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Onchange select input remove error message.

    Dear All,
    Here is my link http://183.78.169.54/v3/addRoute.php. First you need to a simple route name and then press the submit button and do not select the select input values. Then you will see red message appear below it. Now my only problem when I have selected meaning on change I want the error message to disappear. I am stuck here any help please.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,498
    Mentioned
    164 Post(s)
    Tagged
    1 Thread(s)
    I don't know exactly what you mean I guess.

    I first entered a test word into the Route Name field, then hit Submit.
    A couple alert()s
    Got a bunch of red "must not be empty"s

    Then I selected from the 4 drop-downs and hit Submit again.
    A couple alert()s
    After a pause, the error messages went away.

    Are you just not waiting long enough?

  3. #3
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Mitteague,
    Here is the problem "Then I selected from the 4 drop-downs and hit Submit again.A couple alert()sAfter a pause, the error messages went away." What happens is that I do not want to submit again but just by selecting any of the drop down value I want the relevant error message to disappear even before the second time the submit button is hit. Thank you.

    Quote Originally Posted by Mittineague View Post
    I don't know exactly what you mean I guess.

    I first entered a test word into the Route Name field, then hit Submit.
    A couple alert()s
    Got a bunch of red "must not be empty"s

    Then I selected from the 4 drop-downs and hit Submit again.
    A couple alert()s
    After a pause, the error messages went away.

    Are you just not waiting long enough?

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,498
    Mentioned
    164 Post(s)
    Tagged
    1 Thread(s)
    Ah, now I understand.

    The code validates inputs onsubmit OK (tests all 4 in a "batch"?)

    It sounds like for the onchange to work, all four would need to change at the same time - highly unlikely

    I have to go offline for the night soon. But if no one else helps I'll take a closer look when I get a chance tomorrow.

  5. #5
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Mitteague,
    You got my problem right. I want to control on single basis meaning any one change then the relevant message should go off is that possible? I am stuck here.

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    It looks like jQuery's validate already automatically checks dropdown boxes as a part of the onchange event.

    See the radio/checkbox/select demo here.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    To be frank I manage to build read the dynamic validation with the div method. I am just lost now is that how to include the onchange for my dynamic row. So I dont know how the jquery can fit into my codes as below.

    $("input[type='text']").each(function(){
    $(this).change(function(){
    $(this).siblings('div').text('');
    });
    });

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    My question is, your page loads the jQuery validator, so why aren't you using that instead? It already handles the onchange validation that you seem to require.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I saw the example with this line only "<select id="jungle" name="jungle" title="Please select something!" validate="required:true">". Do you think I should change my select input with this addition validate="required:true" will be enough. Just to let you know each of the row of drop down is dynamic. Thank you.

  10. #10
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    From the looks of things, you are loading the jQuery validate library, but you have not told it to do anything. Instead, you seem to have rolled out a completely separate type of hand-written validation routine instead.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  11. #11
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    You are exactly correct. The problem why I did this was I am sorry was totally lost because ealier I put the class=required nothing work so I had no choice work all by myself. So now I have remove all the handwritten stuff and for a test just put for the first drop down box <select class='required' id='locationFrom[]' name='locationFrom[]' >.Can you give me hint how to go about from here?

  12. #12
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Can you give me hint how to go about from here?
    Sure thing. Have a look at the example on the jQuery validate documentation page.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  13. #13
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Ok I have read and put the first step $("#form1").validate();. What I read is that it will automatically validate the form right but not in my case. So what do you think I must do next add more rules is it?

  14. #14
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Ok I have read and put the first step $("#form1").validate();. What I read is that it will automatically validate the form right but not in my case.
    Starting with the HTML basics, the route name doesn't have a required class, so no error message appears for that.

    Also, the default select field has a value of "0" which is considered as a valid value. Make the default option an empty string and that select will be considered to no pass validation, resulting in a correct validation error if it's left as that.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  15. #15
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Once I use the class='required' then how am I going to use my own class which I have set via the .css file. I would like to ask you more about the validate function actually when it will be called only when I submit the form is it and how is this control. Secondly I have done the changes your suggested but if I add new row it does not get validated for the first drop down.

  16. #16
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Adding a new row means that you have introduced a change to the form elements, so you will need to either reinitialize the validate function, or add new rules to the validation.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  17. #17
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    Will it suffice if I add the form.validate() upon each of the new row entry? I have tried that but no changes. So how am I going to apply my custom class to my form elements ?

  18. #18
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    Will it suffice if I add the form.validate() upon each of the new row entry?
    Yes, that should be doable.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  19. #19
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I have done that like this but still not effect. I would like to a bit in depth of this invalidate I thought upon submit it should validate all rows right then why need to reinitiliaze.

    $("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('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', '');


    //$(form).find("dynamicRow").append(prot);
    $("#dynamicRow").find('tbody').append(prot);
    $("#form1").validate();
    return false;
    });

  20. #20
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    I think that the validate plugin ignores any fields that have the same identical name. That may help.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  21. #21
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    So in that case I must rename my individual drop down box but then I will have problem on my php site on reading the values sent via the post method. With now I just send and easily wrap it into an array and can read each row smoothly. What is your best suggestion?

  22. #22
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    What is your best suggestion?
    Use explicit array indexes.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  23. #23
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    I dont understand actually now itself when I add row is different names e.g. prot.find('[name^="locationFrom"]').attr('name', 'locationFrom[' + id + ']');. How will the expilicit index to be implemented?

  24. #24
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by newtomysql View Post
    I dont understand actually now itself when I add row is different names e.g. prot.find('[name^="locationFrom"]').attr('name', 'locationFrom[' + id + ']');. How will the expilicit index to be implemented?
    You should be able to use the unique field name to add new rules that apply to them.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  25. #25
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    873
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear Paul,
    OK I got your idea. Below is what I have tried to do in the function where I add the row itself below first I capture the dropdown name and try to assign the rule of required.I tried this $("#dropLocationFromName")").rules('add', {required: true}); what could be my mistake here.
    var dropLocationFromName = 'locationFrom[' + id + ']';
    //$(form).find("dynamicRow").append(prot);
    $("#dynamicRow").find('tbody').append(prot);
    $("#form1").validate();
    $("#dropLocationFromName").rules('add', {required: true});


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
  •