How to verify the form on the parent page in iframe

Source: Internet
Author: User

Sometimes we need to verify the parent form in iframe, which is actually very simple. In iframe, we can use the parent keyword to call the javascript function of the parent page. The following is an actual problem I encountered in the project. For future convenience, record it. It would be better if it could be useful to everyone.

Iframe Form Design:

<Form name = "add" method = "POST" enctype = "multipart/form-data" action = "ecms. php "onsubmit =" return chkinput (this); "> <input type = hidden value = <? = $ Enews?> Name = enews> <input type = hidden value = <? = $ Classid?> Name = classid> <input name = id type = hidden id = "id" value = <? = $ Id?> <Input type = hidden value = "<? = $ Filepass?> "Name = filepass> <input name = mid type = hidden id =" mid "value = <? = $ Mid?> <? Php @ include ($ modfile);?> <Input type = "submit" name = "addnews" value = "publish" class = "login_button"> </form>

In iframe, write the code for verifying the parent page above and below:

<script type="text/javascript">function chkinput(form){//parent.CheckField();return parent.CheckField();}</script>

Form of the parent page:

<Form name = "classid" id = "classid" method = "post" action = "AddInfo. php "target =" myFrame "onsubmit =" return CheckChangeClass (); "> <select name =" ClassSelector_Type: dbl_Class "id =" ClassSelector_Type_dbl_Class "class =" input "onchange =" ResetClassItem () "> <option value =" 50_0 "> select a large topic </option> <option value =" 58_1 "> real estate information </option> <option value =" 61_1 "> education and Training </option> <option value = "64_1"> Talent Market </option> <option value = "67_1"> life information </option> <option value = "70_1 "> eat, drink, and play </option> <option value =" 73_1 "> dating and marriage </option> <option value =" 75_1 "> local mall </option> <option value =" 76_1 "> vehicle sales </option> <option value =" 85_1 "> household appliances/Digital Communication </option> <option value =" 86_1 "> decoration/home/Building Materials </option> <option value = "87_1"> Financial commerce </option> </select> <select name = "ClassSelector_Type: dbl_ClassItem "id =" ClassSelector_Type_dbl_ClassItem "class =" input "onchange =" ResetClassTypeTradeType (); document. classid. submit (); "> </select> <div style =" display: none; "> <input name =" ClassSelector_Type: txt_ClassId "type =" text "value =" 50 "id =" ClassSelector_Type_txt_ClassId "/> <input name =" ClassSelector_Type: txt_TypeId "type =" text "value =" 50_0 "id =" ClassSelector_Type_txt_TypeId "/> <input name =" ClassSelector_Type: txt_TradeType "type =" text "value =" 2 "id =" ClassSelector_Type_txt_TradeType "/> </div> (select a topic for easy information Review) </form>

Form Verification code on the parent page:

<Script language = "JavaScript"> function aa () {alert ("OK! "); Return false;} function CheckField () {var form_class_id = document. getElementById ("inline"); // alert (form_class_id.value); if (form_class_id.value = '50' | form_class_id.value = '') {alert (" select a topic "); return false;} return true;} </script>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.