0

I am creating input fields with jquery

var randomNum = Math.ceil(Math.random() * 99999);        
    $("<p class='" + randomNum + "'>First name: <input type='text'  name='kontaktFormaIme" + randomNum + "' class='required' id='kontaktFormaIme" + randomNum + "' maxlength='50' /></p>").appendTo(".kontakt");
    $("<p class='" + randomNum + "'>Last NameIme: <input type='text'  name='kontaktFormaPrezime" + randomNum + "' class='required' id='kontaktFormaPrezime" + randomNum + "'  /></p>").appendTo(".kontakt");

with this I can creat as many as I want

What is easy way to check for example every with ID that starts with "kontaktFormaIme" or have class 'required'

This is good example

But I don' know how to make general checker, I have tried something like this but it is not working

function ValidateKontakt(source, args) {
    var isFormValid = true;
    $(".required input").each(function () {
        if ($.trim($(this).val()).length == 0) {                
            $(this).addClass("highlight");
            isFormValid = false;
        }
        else {
            $(this).removeClass("highlight");
        }
    });
    args.IsValid = isFormValid;
}
5
  • what does you mean by not working? any error check in Error log Commented May 18, 2012 at 12:49
  • looks like $(".required input") wasn't good selector, but your sugestion worked like charm Commented May 18, 2012 at 12:57
  • good! you can also vote up ;) Commented May 18, 2012 at 12:59
  • I can't :( I need 15 points to do that Commented May 18, 2012 at 13:00
  • no worries you can do it any time wherever you can.. Commented May 18, 2012 at 13:05

1 Answer 1

1

you can select the HTML element using jQuery startsWith selector..

$("input[id^='kontaktFormaIme']")

I may be wrong with quotes. please take care of it...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.