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;
}
Community
  • 1
  • 1
Nikola Gaić
  • 117
  • 1
  • 11

1 Answers1

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...

Murtaza
  • 3,045
  • 2
  • 25
  • 39