Mutual value transfer method for the parent form of a javascript subform

Source: Internet
Author: User

The script is a simplified version. In general, many cms have such functions. This function is also used in the selection related articles in dedecms. The specific code is given below.
Core code of the parent page:
Copy codeThe Code is as follows:
<Script>
Function SelectArcListA (fname ){
Var posLeft = 10;
Var posTop = 10;
Window. open ("content_select_list.asp? F = "+ fname +" & k = "+ form1.keyword. value, "selArcList", "scrollbars = yes, resizable = yes, statebar = no, width = 700, height = 500, left =" + posLeft + ", top = "+ posTop );
}
</Script>
<Input name = "lsel" type = "button" id = "lsel" class = "nbt" style = "width: 150px "onChange =" "value =" select from published documents... "onClick =" SelectArcListA ('form1. xiangguanid '); ">

Core code of the sub-page:
Copy codeThe Code is as follows:
<SCRIPT language = javascript>
// Obtain the name of the selected file
Function getCheckboxItem ()
{
Var allSel = "";
If (document. form2.arcID. value) return document. form2.arcID. value;
For (I = 0; I <document. form2.arcID. length; I ++)
{
If (document. form2.arcID [I]. checked)
{
If (allSel = "")
AllSel = document. form2.arcID [I]. value;
Else
AllSel = allSel + "," + document. form2.arcID [I]. value;
}
}
Return allSel;
}
Function selAll ()
{
For (I = 0; I <document. form2.arcID. length; I ++)
{
If (! Document. form2.arcID [I]. checked)
{
Document. form2.arcID [I]. checked = true;
}
}
}
Function noSelAll ()
{
For (I = 0; I <document. form2.arcID. length; I ++)
{
If (document. form2.arcID [I]. checked)
{
Document. form2.arcID [I]. checked = false;
}
}
}
Function ReturnValue ()
{
If(registry.opener.doc ument. form1.xiangguanid. value = ""){
Required parameter opener.doc ument. form1.xiangguanid. value = getCheckboxItem ();
}
Else {
Required parameter opener.doc ument. form1.xiangguanid. value + = "," + getCheckboxItem ();
}
Alert ("the selected ID is successfully added, you can continue to add ");
// Window. opener = true;
// Window. close ();
}

The following is the html code. <input type = "checkbox" name = "arcID" value = "<% = rs (" id ") %>"> output id
Copy codeThe Code is as follows:
<A class = inputbutx
Href = "javascript: selAll ()"> select all </A> <A class = inputbutx
Href = "javascript: noSelAll ()"> cancel </A> <A class = inputbutx
Href = "javascript: ReturnValue ()"> Add the selected value to the list </A>

The following is a supplement:
// Mode form value passing

<! -- ===== Parent window, I name it parentform.html ====-->
Copy codeThe Code is as follows:
<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<HEAD>
<Title> confirm data input in the pop-up window and return to the parent form-main form </title>
<Meta name = "Generator" CONTENT = "EditPlus">
<Meta name = "Author" CONTENT = "jb 51.net">
<Meta name = "Keywords" CONTENT = "">
<Meta name = "Description" CONTENT = "">

<Script language = "javascript" type = "text/javascript">
Function doInput ()
{
Var win = window. showModalDialog ("Childform.html", window, "dialogWidth = 500px; dialogHeight = 300px; center = yes; status = no ");
If (win! = Null)
{
Document. getElementById ("parentTextBox"). value = win;
}
}
</Script>

</Head>
<Body> input data in the new pop-up form and transfer it to the parent form.
<Br/>
<Br/>
<Br/>
<Input type = "text" id = "parentTextBox"/> <a href = "javascript: doInput ()"> click here to bring up a subform </a>
</BODY>
</HTML>

<! -- =============== Parent form code end ======================== -->

<! -- ======= Sub-form: named childform.html ======== -->
Copy codeThe Code is as follows:
<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<HEAD>
<Title> confirm data input in the pop-up window and return it to the parent form-child form </title>
<Meta name = "Generator" CONTENT = "EditPlus">
<Meta name = "Author" CONTENT = "qiujy">
<Meta name = "Keywords" CONTENT = "">
<Meta name = "Description" CONTENT = "">
<Base target = "_ self">
</Head>
<Body topmargin = "0" leftmargin = "0" scroll = "no">
</Br>
<Input type = "text" id = "childTextBox"/>
</Br>
<A href = "javascript: doPassToParent ()"> click here to return </a>
</BODY>
</HTML>
<Script language = "javascript" type = "text/javascript">
Document. getElementById ("childTextBox"). value = maid. Doc ument. getElementById ("parentTextBox"). value;
Function doPassToParent ()
{
If (document. getElementById ("childTextBox"). value. length <= 0)
{
Alert ("Enter data ");
Return;
}
Window. returnValue = document. getElementById ("childTextBox"). value;
Window. close ();

}
</Script>

// Pass values to the child form and parent form

1. Create two pages. One is Parent.html.
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> parent form </title>
<Script language = "javascript" type = "text/javascript">
Function OpenWindow (){
Using multiple open('son.html ');
}
Function setValue (m_strValue ){
Document. getElementById ("txt_Value"). value = m_strValue;
}
</Script>
</Head>

<Body>
<Form id = "form1" name = "form1" method = "post" action = "">
<Label>
<Input type = "text" name = "txt_Value" id = "txt_Value"/>
</Label>
<Label>
<Input type = "button" name = "btn_ShowClose" id = "btn_ShowClose" value = "button" onclick = "OpenWindow ();"/>
</Label>
</Form>
</Body>
</Html>

The other is the subform:
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> subform </title>
<Script language = "javascript" type = "text/javascript">
Function CloseWind (){
Opener. setValue ("pass value to parent form ");
Window. close ();
}
</Script>
</Head>

<Body>
<Form id = "form1" name = "form1" method = "post" action = "">
<Label> disable
<Input type = "button" name = "btn_Close" id = "btn_Close" value = "button" onclick = "CloseWind ();"

/>
</Label>
</Form>
</Body>
</Html>

2. Use the setValue (m_strValue) of the parent form executed by the child form to perform the value assignment operation.

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.