2

so here's my problem.

i have a html page with a simple form and some javascript (jquery) code to validate it, ok then.

this page would looks like this: test.html

<html>
<head>
<title></title>
<script  src="jquery-1.7.min.js" type="text/javascript"></script>
<script type="text/javascript">

function validate(){
    $('form').submit(function () {
        var txt = $('#SYSTEM_NAME').val();
        if (txt == '') $('#loading').append('field is empty');
        return false;
    })

}

window.onload = validate

<form action="SomeAction" id="form0" method="post">

    <fieldset>
        <legend>Information</legend>

        <div class="editor-field">
            <input id="SYSTEM_NAME" name="SYSTEM_NAME" type="text" value="" />
        </div>

        <input type="submit" value="Insert" id="saveCreation" />
        <div id="loading"></div>

    </fieldset>

</form>

</body> 
</html>

In this page above, if you try to insert without any information on the field 'SYSTEM_NAME', it would dysplay a message. Everything is fine here my form is validated.

But when i load this page from another one using ajax(jquery), what occurs is, after loaded it the validation that i made on 'test.html' doenst work.

Example:

<html>
<head>
<title></title>
<script  src="jquery-1.7.min.js" type="text/javascript"></script>
<script type="text/javascript"> 
$('#go').click(function(){
    $('#here').load('test.html')
}); 
</script>
</head>
<body>
<input type='button' id='go' value='go' />
<div id='here'></div>
</body>
</html>

Now if i click on 'Insert' the validation doest work anymore.

How can i solve this problem ? can i interact with loaded page and javascript code together ?

Hope you guys have understood my problem. Thanks and sorry for enlish mistakes.

1 Answers1

0

forgive me if this is too much of a change, but i thought i might suggest another method for you. what about using jquery validate to help you with the validation? here is an example with the ajax-response validating as you want. below is the parent document... (notice that i am including jquery validate in the head. just ignore the 'get_test' i am using to load the partial.)

<!DOCTYPE html>
<html>
<head>
  <title></title>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
  <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js" type="text/javascript"></script>
  <script type="text/javascript">

    $(document).ready(function() {

      $('#go').click(function() {
        $('#here').load('get_test');
      });

    }); 

  </script>

</head>
<body>

<input type='button' id='go' value='go' />
<div id='here'></div>
</body>
</html>

and the partial i am loading below... (notice that the text input has a class of 'required' - this is how jquery validate works. you will also see a validate method.)

<script type="text/javascript">
  $("#form0").validate();
</script>

<form action="SomeAction" id="form0" method="post">

    <fieldset>
        <legend>Information</legend>

        <div class="editor-field">
            <input id="SYSTEM_NAME" name="SYSTEM_NAME" type="text" value="" class="required" />
        </div>

        <input type="submit" value="Insert" id="saveCreation" />
        <div id="loading"></div>

    </fieldset>

</form>
Sean M
  • 1,990
  • 20
  • 16