-3

I wanna create a form in js file.

var form = '<form id="formForgetPass" action="#" method="POST" class="form-horizontal"><div class="form-group" style="margin-bottom: 0px !important;"><label for="textfield" class="control-label col-sm-2">E-posta</label><div class="col-sm-10"><input type="text" id="forgetEmail" name="email" class="form-control" /></div></div></form>';

And I'm using JquerValidation

Is it possible that I could control form inputs at run-time? I haven't figured out that.

It did not work properly as below

    $("#formForgetPass").validate({
    rules: {
        email: {
            required: true,
            email: true
        }
    }
});
Enes Pekkaya
  • 304
  • 2
  • 3
  • 14

2 Answers2

0
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  var form = '<form id="formForgetPass" action="#" method="POST" class="form-horizontal"><div class="form-group" style="margin-bottom: 0px !important;"><label for="textfield" class="control-label col-sm-2">E-posta</label><div class="col-sm-10"><input type="text" id="forgetEmail" name="email" class="form-control" /></div></div></form>';

$("#MainDiv").append(form);
alert($("#forgetEmail"));

});
</script>
</head>
<body>

<div id="MainDiv">
</div>

</body>
</html>

U can attach into div element and get the elements. This alert will return the object.

0
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  var form = '<form id="formForgetPass" action="#" method="POST" class="form-horizontal"><div class="form-group" style="margin-bottom: 0px !important;"><label for="textfield" class="control-label col-sm-2">E-

posta</label><div class="col-sm-10"><input type="text" id="forgetEmail" name="email" class="form-control" /></div></div></form>';

$("#MainDiv").append(form);
});

function uivalidate() {
    if  ($("#forgetEmail").val() =='' ) {
        alert(" Value Should not be empty !");
        return false;
    }
    alert('The value - ' +  $("#forgetEmail").val());
}
</script>
</head>
<body>

<div id="MainDiv">
</div>
<br>
<button type="button" onClick="uivalidate();">Click Me!</button>
</body>
</html>

    **Hi we can validate like this... this is question u r asking... give me the clarity**