A multiple search + multiple-pass value solution _javascript tips

Source: Internet
Author: User
Little brother just learn js, hope Master can help!
This is a management system of the project participants in the selection of code, to solve the problem is:

1. When the user clicks on the selection, a new window pops up, can find someone by name or organization, and then select the person you want to select. Then continue to find the next person. Then select.
2 After selecting the person you want to select, return the value to the person's form on the main page
There may be more than one field in 31 forms that needs to be filled in.


For example, to add a project information now

which have
Project Moderator
Project team member
The personnel information is obtained from the personnel database.


The following is the code for the main page, because of the ifrma. So you can't pass the value.

File Pack up:
Http://www.HNTF.CN/RYXZ.rar
<script language= "JavaScript" > var t function disp (obj) {ctltoplacevalue = obj docu ment.all.iframe1.style.display= "Block"; function Shout () {document.all.iframe1.style.display= ' none '; } T=DOCUMENT.FRMXX.NRYGXM function List_sub () {//Get the ID value of the selected employee in IFRAME1 var List_value_str,list_array; var n = 0; List_array = Document.employee.document.all.item ("employee_id"); for (var i=0; i<list_array.length; i++) {if (Document.employee.document.all.item ("employee_id", i) . checked) {var value_str; Value_str = Document.employee.document.all.item ("employee_id", I). ID; n = n + 1; if (n = = 1) {list_value_str = Value_str; }else{list_value_str = List_value_str + "," + value_str; } }End If}//end for//document.write (LIST_VALUE_STR); DOCUMENT.EMPLOYEE2.DOCUMENT.FORM1.TEXT_VALUE.VALUE=LIST_VALUE_STR; T.VALUE=LIST_VALUE_STR; Document.all.iframe1.style.display= "None"; The function list_sub1 () {//Gets the ID value of the selected employee in IFRAME1 var List_value_str,list_array; var n = 0; List_array = Document.employee.document.all.item ("employee_id"); for (var i=0; i<list_array.length; i++) {if (Document.employee.document.all.item ("employee_id", i) . checked) {var value_str; Value_str = Document.employee.document.all.item ("employee_id", I). ID; n = n + 1; if (n = = 1) {list_value_str = Value_str; }else{list_value_str = List_value_str + "," + value_str; } }//end if}//end for document.getElementById ("pre"). I Nnerhtml=document.getelementbyid ("Pre"). Innerhtml+list_value_str; document.write (LIST_VALUE_STR); DOCUMENT.EMPLOYEE2.DOCUMENT.FORM1.TEXT_VALUE.VALUE=LIST_VALUE_STR; function List_sub2 () {list_value_str = ""; document.getElementById ("Pre"). Innerhtml= ""; document.write (LIST_VALUE_STR); DOCUMENT.EMPLOYEE2.DOCUMENT.FORM1.TEXT_VALUE.VALUE=LIST_VALUE_STR; } </script> </pead> <style type= "Text/css" > <!--. STYLE2 {font-size:14px; Font-weight:bold; }. menu1 {border-right: #000000 2px solid; Border-top: #adbac9 2px solid; Border-left: #adbac9 2px solid; COLOR: #ffffff; Border-bottom: #000000 2px solid; Background-color: #637994;p osition:absolute; } #iframe1 {position:absolute; left:197px; top:218px; width:459px; height:280px; Z-index:1; --> </style> <body > <div class= "menu1" id= "iframe1" > <table width= "100%" border= "0" ce llspacing= "0" cellpadding= "0" > <tr> <td><table width= "100%" border= "0" cellpadding= "0" cells pacing= "0" > <tr> <td><table width= "100%" border= "0" cellpadding= "0" cellspacing= "0" class= "titlebar" > <tr> <td><span class= "STYLE2" > select people </span></td& Gt </tr> </table> <table width= "98%" border= "0" align= "center" cellpadding= "6" cel lspacing= "0" > <tr> <td height= "><div class=" titlebar "Id=pre" name=pre></div> <div align= "right" > <input name= "but" Ton3 "TyPe= "button" class= "header_btn" onclick= "javascript:list_sub1 ();" value= "continue to submit" > <input nam E= "Button4" type= "button" class= "header_btn" onclick= "Javascript:list_sub" (); "value=" Select Completed > <input name= "button5" type= button "class=" header_btn "onclick=" javascript:list_sub2 (); "Value= Empty" > <input name= "button" type= "button" class= "header_btn" onclick= "javascript:shout ();" Value= "Off" > </div></td> </tr> </table > <iframe src= "http://www.hnkjc.com/project/y_1.asp" name= "Employee" height= "" width= "100%" border= 1></iframe></td> </tr> </table></td> </tr> </table> </div> <form action= ' pro_add_save.asp ' method=post name=frmxx id= ' frmxx ' > <p> personnel <input N Ame= "RY2" type= "text" Disabled class= "input" Id= "RY2" > <input type= "button" Name= "Submit" onclick= "Javascript:disp (frmxx. NRYGXM); "-value=" select "> </p> <p> Personnel 2 <input name=" RY2 "type=" text "Disabled class=" input "Id=" RY2 "> <input type=" button "Name=" Submit2 "onclick=" Javascript:disp (frmxx. NRYGXM); "-value=" Options "> </p> </form> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Temporary Solution with Ajax implementation
I found a better way, the basic idea is js+ajax to achieve
, personally feel that this way to solve multiple searches, many times better, the choice of the JS code is from a worry-free copy, if there is a better way, hope expert advice! Because in the Office system input data, often encountered this problem, VBS solution is very laborious.
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <meta http-equiv=" Content-type "Conte Nt= "text/html; Charset=utf-8 "/> <title> Untitled document </title> <style type=" Text/css "> <!--. L {font-size: 10pt;} --> </style> <script language= "JavaScript" > var xmlobj = false; var Xmlresult; try {xmlobj=new XMLHttpRequest; catch (e) {try {xmlobj=new ActiveXObject ("MSXML2. XMLHTTP "); catch (E2) {try {xmlobj=new ActiveXObject ("Microsoft.XMLHTTP"); catch (E3) {xmlobj=false; }} if (!xmlobj) {alert ("XMLHttpRequest init failed!"); function Ajaxsearch () {var searchword; Searchword=escape (document.getElementById ("Searchword"). Value); if (searchword== "") {document.getElementById ("Search_result"). innerhtml= "<ul><li> Please enter the keyword!</li></ul>"; Return document.getElementById ("Search_result"). Innerhtml= "<ul><li> loading, please wait </li></ul>"; Xmlobj.open ("POST", "ajaxsearch.asp", true); Xmlobj.setrequestheader ("Content-type", "application/x-www-form-urlencoded"); Xmlobj.onreadystatechange=function () {if (xmlobj.readystate==4) {if (xmlobj.status==200) { Xmlresult=xmlobj.responsexml; Ajaxshowresult (); }} xmlobj.send ("searchword=" +searchword); function Ajaxshowresult () {var results,i,strtemp; Results=xmlresult.getelementsbytagname ("result"); strtemp= "<ul>"; if (Results[0].getelementsbytagname ("Logid") [0].firstchild.data== "#") strtemp=strtemp+ "<li> No search results </li > "; else for (i=0;i<results.length;i++) sTrtemp = strtemp + "<li>" +results[i].getelementsbytagname ("Logtitle") [0].firstchild.data+ "<input type=\" Checkbox\ "name=\" activity\ "id=\" activity_1\ "value=\" "+results[i].getelementsbytagname" ("Logid") [0]. firstchild.data+ "\" > "+ results[i].getelementsbytagname (" Logtitle ") [0].firstchild.data +] (" +results[i] ". getElementsByTagName ("Logtitle2") [0].firstchild.data + "] </li>"; strtemp=strtemp+ "</ul>"; document.getElementById ("Search_result"). InnerHTML = strtemp} var likes=new Array (); Xinge=new Array (); function AddThis (e) {var e, Srce, op, opt, I; E=window.event?window.event:e; Srce=e.srcelement?e.srcelement:e.target; if (!srce) return; if (String (srce.tagname). toLowerCase ()!= "Input" | | String (Srce.type). toLowerCase ()!= "checkbox") return; if (SrcE.id.indexOf ("Xinge")!=-1) {op=xinge; Opt=document.forms[0].xinge}else{op=likes; opt=document.forms[0]. Likes; } if (srce.checked) {i=-1; while (Op[++i]) if (op[i]==srce.value) return; Op[i]=srce.value; }else{I=-1; while (Op[++i]) if (op[i]==srce.value) {op.splice (i,1); i--;} } Opt.value=op; } document.onkeydown=document.onchange=document.onclick=addthis; </script> </pead> <body> <form name= "Form1" ><textarea name= "likes" "cols=" rows = "3" id= "textarea9" ></textarea> <table border= "0" width= "100%" cellspacing= "0" cellpadding= "0" > <tr> <td> </td> </tr> </table> </form> <div> <div align= "center" > <input name= "Searchword" type= "text" class= "input" id= "Searchword" onchange= "Aja Xsearch (); "onkeydown=" if (event.keycode==13) Ajaxsearch (); "/> <input type=" button "class=" Header_btn "OnCli Ck= "Ajaxsearch ();" value= "Search"/> </div> </div> <div id= "Search_result" > <ul><li& gt; Please enter the keyword </li></ul> </div> </Body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

ajaxsearch.asp
<!--#INCLUDE file= "connectdb2.asp"--> <% ' connectdb2.asp for database connection files Dim search_word,xml_result,rssearch,sqls Earch Set rssearch=server.createobject ("ADODB. RecordSet ")" Get search keyword Search_word=trim (Request ("Searchword")) ' XML document Header xml_result= ' <?xml version= ' "1.0" "encoding=" "gb2312" "?><blogsearch>" IF search_word<>empty Then ' Create query SQL statement sqlsearch= ' SELECT * from wuhen_t _yg WHERE ygxm like '% ' &Search_Word& '% ' ORDER by YGBH DESC ' open recordset Rssearch.open sqlsearch,conn,1,1 ' If no search results produce a result, Logid is #, marking no search results if Rssearch.bof and rssearch.eof Then xml_result=xml_result& ' <result> <logid>#</logid><logtitle/></result> "' Cyclic output search results do, not rssearch.eof XML _result=xml_result& "<result><logid>" &rssearch ("YGBH") & "</logid><logtitle> <! [cdata["&rssearch (" Ygxm ") &"]]></logtitle><logtitle2><! [cdata["&rssearch" ("DW")& "]]></logtitle2></result>" ' Loop output rssearch.movenext loop Else ' keyword is empty, returns no search Result xml_result=xml_result& "<result><logid>#</logid><logtitle/></result>" End IF X ml_result=xml_result& ' </blogsearch> ' sets MIME type to XML document Response.ContentType = ' Application/xml ' Response . CharSet = "Utf-8" Output search Results Response.Write (xml_result)%>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

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.