0

I have one html structure

<form id="myvalidation">
<iframe>
<form  id="insidevalidation">
<input type="text" name="myname" id="myname" />
</form>
</iframe>
<input type="submit" />

</form>

I need to validate input field which is inside the iframe but i am not able to find the name for validation from outside the iframe.

 "myname": {
                            required:true,
                            validEmail:true
                            //onlyNumeric:true
                        },

Not sure how to get mynamefrom outside the iframe. please help

supersaiyan
  • 1,670
  • 5
  • 16
  • 36

1 Answers1

0

As long as the input has a name, you do not need to know the name to declare rules using the .rules() method.

After initializing the plugin with .validate(), you can attach the .rules() method to any selector.

$('#insidevalidation').validate({ // initialize plugin
    // other options, etc.
    ....
});

$('#insidevalidation input').rules('add', { // attach these rules to FIRST input element
    required: true,
    validEmail: true
});

Also note that your submit button is outside of the form you're trying to validate so it's not going to work as expected.


However, my answer assumes that you can use this plugin on a form within an iframe. I don't know, and it cannot be tested within an SO snippet or a jsFiddle since the iframe is rendering empty.

Sparky
  • 98,165
  • 25
  • 199
  • 285