提交按钮而不点击它

时间:2015-12-20 01:42:48

标签: javascript html jsp

我有一个搜索它的主页,它包含文本框和按钮..(第1页)

另一个页面还有一个文本框和按钮,当我按下搜索时,会有一个iframe显示结果..(第2页)。

我的想法是当我在第1页输入文本并按下提交按钮时,我想转到第2页并将第1页中输入的文本复制到第2页中的文本框并提交按钮而不按下提交按钮。

我复制了文字,但我不知道如何提交按钮?

Page 2代码:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> BAK </title>
<script> 
    function show() { 

        if(document.getElementById("adv").innerHTML == "+")
        {
            if(document.getElementById('benefits').style.display=='none') 
            { 
                document.getElementById('benefits').style.display='block';
                document.getElementById("adv").innerHTML = "-";
            }
        }
        else
        {
            if(document.getElementById('benefits').style.display=='block') 
            { 
                document.getElementById('benefits').style.display='none'; 
                document.getElementById("adv").innerHTML = "+";
            }
        }

        return false;
    } 

    document.theForm.submit();

</script> 
<style>
#searchbox
{
    background-color: #eaf8fc;
    background-image: linear-gradient(#fff, #d4e8ec);
    border-radius: 35px;    
    border-width: 1px;
    border-style: solid;
    border-color: #c4d9df #a4c3ca #83afb7;            
    width: 525px;
    height: 35px;
    padding: 6px;
    margin: 0px auto 20px;
    overflow: hidden; /* Clear floats */
}
#search, #submit {
    float: left;
}

#search {
    padding: 7px 0.5px;
    height: 35px;
    width: 380px;
    border: 1px solid #a4c3ca;
    font: normal 13px 'trebuchet MS', arial, helvetica;
    background: #f1f1f1;
    border-radius: 50px 3px 3px 50px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25) inset, 0 1px 0 rgba(255, 255, 255, 1);      
    padding: 6px;
}

#submit
{       
    background-color: #6cbb6b;
    background-image: linear-gradient(#95d788, #6cbb6b);
    border-radius: 3px 50px 50px 3px;    
    border-width: 1px;
    border-style: solid;
    border-color: #7eba7c #578e57 #447d43;
    box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 
                0 1px 0 rgba(255, 255, 255, 0.3) inset;
    height: 35px;
    margin: 0 0 0 10px;
    padding: 0;
    width: 90px;
    cursor: pointer;
    font: bold 14px Arial, Helvetica;
    color: #23441e;    
    text-shadow: 0 1px 0 rgba(255,255,255,0.5);
}

#submit:hover {       
    background-color: #95d788;
    background-image: linear-gradient(#6cbb6b, #95d788);
}   

#submit:active {       
    background: #95d788;
    outline: none;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;        
}

#submit::-moz-focus-inner {
       border: 0;  /* Small centering fix for Firefox */
}

label input {
  display: none;/* <-- hide the default checkbox */
}
label span {/* <-- style the artificial checkbox */
  height: 15px;
  width: 15px;
  border-radius:17px;
  border: 1px solid grey;
  display: inline-block;
  position: relative;
}
[type=radio]:checked + span:before {/* <-- style its checked state..with a ticked icon */
  content: '\2714';
  border-radius:17px;
  position: absolute;
  top: -2px;
  left: 0;
  background: #0C6;
}
[type=checkbox]:checked + span:before {/* <-- style its checked state..with a ticked icon */
  content: '\2714';
  border-radius:17px;
  position: absolute;
  top: -2px;
  left: 0;
  background: #FFCC00;
}
.ss {
    font-family: 'Helvetica Neue';
    font-size: 18px;
    font-style: italic;
    font-variant: normal;
    font-weight: bold;
    line-height: 22px;

}
html {
    overflow-y: hidden; 
}
a{
    background-color: #FFFFFF;
    background-image: linear-gradient(#95d788, #FFFFFF);
    border-radius: 50px 50px 50px 50px;    
    border-width: 1px;
    border-style: solid;
    border-color: #7eba7c #578e57 #447d43;
    box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 
                0 1px 0 rgba(255, 255, 255, 0.3) inset;
    height: 33px;
    margin: 0 0 0 10px;
    padding: 0;
    width: 30px;
    cursor: pointer;
    font: 28px Arial, Helvetica;
    color: #23441e;    
    text-shadow: 0 1px 0 rgba(255,255,255,0.5);
    float: left;
    text-decoration: none;
}
a:hover {       
    background-color: #95d788;
    background-image: linear-gradient(#FFFFFF, #95d788);
}   

a:active {       
    background: #95d788;
    outline: none;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;        
}

a::-moz-focus-inner {
       border: 0;  /* Small centering fix for Firefox */
}
</style>

</head>

    <body>
    <form name="theForm" method="post" action="results_Page.jsp" target="iframe">
    <%
        String textSearch = request.getParameter("txtbox").toLowerCase();
    %>
    <div align="center" id="searchbox">
        <input id="search" type="text" placeholder="  Type here.." value="<%=textSearch %>" name="txtbox">
        <input id="submit" name="submit" type="submit" value="Search">
    <a id="adv" href="1" alt="Advance Search" name="1" onclick="return show();">+</a>
    </div>

    <div align="center" class="ss">


    <div id="benefits" style="display:none;">    
     <table  cellpadding="5">
           <tr>
            <td>
            <label>    Search Using :    </label>
            </td>
            <td>
            <label><input type="radio" name="se" id="op1" value="boolean_retrieval" checked="checked"><span></span>  boolean_retrieval    </label>
            </td>                   
            <td>
            <label><input type="radio" name="se" id="op2" value="Inverted_Index" />  <span></span>  Inverted Index model    </label>
            </td>
            <td>
            <label><input type="radio" name="se"  id="op3" value="Posting_Lists" />  <span></span>  Posting Lists model </label>
            </td>
           </tr>

           <tr>
            <td>
            <label>    Options :    </label>
            </td>
            <td>
            <label><input type="checkbox" name="op1"  id="op4" value="stop_words">  <span></span>  Stop word    </label>
            </td>                       
            <td>
            <label><input type="checkbox" name="op2"  id="op5" value="wordNet" />  <span></span>  wordNet   </label>
            </td> 
            <td>
            <label><input type="checkbox" name="op3"  id="op6" value="stemming" />  <span></span>  Porter Stemmer    </label>
            </td>
            <td>
            <label><input type="checkbox" name="op4"  id="op7" value="reIndexing" />  <span></span>  Re-Indexing    </label>
            </td> 
           </tr>
    </table>
    </div>
    </div>

    <div>
        <hr> 
         <iframe  name="iframe" src="iframeImage.html" height="500px" width="100%" style=" border-width: 0; image-resolution: snap;" > </iframe>

    </div>

    </form>

</body>
</html>

Results_Page.JSP代码:

<%@page import="java.util.Arrays"%>
<%@page import="java.util.List"%>
<%@page import="org.jsoup.parser.Parser"%>
<%@page import="org.jsoup.nodes.Element"%>
<%@page import="org.jsoup.select.Elements"%>
<%@page import="org.jsoup.Jsoup"%>
<%@page import="org.jsoup.nodes.Document"%>
<%@page import="java.util.StringTokenizer"%>
<%@page import="java.io.FileReader"%>
<%@page import="java.io.BufferedReader"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.io.File"%>
<%@page import="Search.searchEngine"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title> == BAK Results == </title>
    </head>
    <body>
        <div>

            <h2> ${param.txtbox}  </h2>


                <%
                    List<String> stopwordsList = Arrays.asList("a", "able", "about",
            "across", "after", "all", "almost", "also", "am", "among", "an",
            "and", "any", "are", "as", "at", "be", "because", "been", "but",
            "by", "can", "cannot", "could", "dear", "did", "do", "does",
            "either", "else", "ever", "every", "for", "from", "get", "got",
            "had", "has", "have", "he", "her", "hers", "him", "his", "how",
            "however", "i", "if", "in", "into", "is", "it", "its", "just",
            "least", "let", "like", "likely", "may", "me", "might", "most",
            "must", "my", "neither", "no", "nor", "not", "of", "off", "often",
            "on", "only", "or", "other", "our", "own", "rather", "said", "say",
            "says", "she", "should", "since", "so", "some", "than", "that",
            "the", "their", "them", "then", "there", "these", "they", "this",
            "tis", "to", "too", "twas", "us", "wants", "was", "we", "were",
            "what", "when", "where", "which", "while", "who", "whom", "why",
            "will", "with", "would", "yet", "you", "your");

                   String textSearch = request.getParameter("txtbox").toLowerCase();
                   String type = request.getParameter("se");
                   String option1 = request.getParameter("op1");
                   String option2 = request.getParameter("op2");
                   String option3 = request.getParameter("op3");
                   String option4 = request.getParameter("op4");


                   searchEngine obj = new searchEngine();
                   obj.search(textSearch, type,option1,option2,option3,option4);


                   ArrayList allFiles = new ArrayList();
                   allFiles = (ArrayList<Object>)(obj.getAllFilesArray()).clone();

                   if(allFiles.size() < 1)
                   {
                       %>
                            <div align="left" style=" margin-left: 310px;"> 
                                <h4 color="#E8E8E8"> <%="About " + allFiles.size() + " Results." %> </h4> 
                            </div>
                        <%
                   }
                   else
                   {
                       for(int i=0;i < allFiles.size();i++) {
                        File xmlFiles = new File((String)(allFiles.get(i)) );
                        BufferedReader br = new BufferedReader(new FileReader(xmlFiles));

                        StringBuilder xmlAsText = new StringBuilder();
                        String line = "";
                        line = br.readLine();
                        while (line != null) {
                           xmlAsText.append(line);
                           xmlAsText.append("\n");
                           line = br.readLine();
                        }
                        StringTokenizer descTokenizer = null;
                        Document doc = Jsoup.parse(xmlAsText.toString(),"",Parser.xmlParser());

                        String image = doc.select("IMAGE").first().text();
                        Elements titles = doc.getElementsByTag("TITLE");
                        String titlesText = "";
                        Elements descriptions = doc.getElementsByTag("DESCRIPTION");

                        File desktopDir = new File(System.getProperty("user.home"), "Desktop");
                        String ImagePath="",FilePath="";
                        ImagePath = "ImageServlet?data=" + desktopDir.getPath() + "\\IRDataset\\iaprtc12\\" + image;
                        FilePath = "FilesServlet?data=" + allFiles.get(i).toString();


                        String Desc="";
                        if(descriptions.size() > 0)
                        {
                            descTokenizer = new StringTokenizer(descriptions.get(0).text()," ");
                            while (descTokenizer.hasMoreTokens())
                            {
                                String word = descTokenizer.nextToken();

                                if(Desc.length() < 100)
                                {
                                    Desc += word +" ";
                                }
                                else
                                {
                                    Desc += " ..";
                                    break;
                                }
                            }
                            %>
                            <%
                                if(i == 0)
                                {
                                    %>
                                    <div align="left" style=" margin-left: 310px;"> 
                                        <h4> <%="About " + allFiles.size() + " Results." %> </h4>
                                    </div>
                                    <%
                                }
                            %>
                            <a href="<%=FilePath %>" style="color: black">

                            <div align="left" style=" margin-left: 310px;">
                                <div align="left" style="display:inline-block;vertical-align:top;"> 
                                <img height="80px" width="80px" src="<%=ImagePath %>" alt="<%=titles.get(0).text()%>"/>
                                </div>
                                <div align="left" style="display:inline-block; margin-left: 20px">
                                    <div><h3> <%=titles.get(0).text() + titlesText%> </h3> </div>
                                    <div><p><%=Desc%></p></div>
                                </div>
                            </div>
                            </a>
                                <br/>
                            <%
                        }
                    }
                   }





                %>

        </div>
    </body>
</html>

1 个答案:

答案 0 :(得分:2)

更改要提交的搜索按钮类型。

<script src="https://www.google.com/jsapi"></script>
<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry,places&ext=.js"></script>
<div id="elevation-chart"></div>
<div id="map"></div>

然后:

<input id="search" type="submit" placeholder="  Type here.." value="<%=textSearch %>" name="txtbox">