In site search (special one :p ), a bit complicated...

dragonlube

Elite Member
Jr. VIP
Joined
Jan 22, 2011
Messages
3,691
Reaction score
781
hey,

I am trying to figure out how to have an input box in my main page that will be used "like" a site search engine but what I want is for the result page to automatically input the value from the box in a particular place in the resulted page, also it needs to have just one page result and just link directly to it, not to actually have a results list.

thanks
 
So you want to have like a fake search box? One that no matter what the user types in it will always return a static results page instead of real search results?

Just checking to be sure I'm clear what your looking for.
 
Actually I was thinking to have the input from the box on the main page automatically go into another box in the 2nd page so the user wont have to fill it out twice.

basically it would be a 2 page filling form, the 1st page would have only 1 box and the 2nd page would have the first box (already filled from 1st page) plus some more input boxes for additional info needed.

hope that makes sense,
thanks
 
OK, if you want to pass much data then you'll need to use php, but if it's just info from a single input box then you can use javascript and pass it to the next page using just the url.

I found a page that can help you out. This site explains both ways to pass data collected from one page on to the next page. The examples use static data since they're just showing how to pass the data. You'll have to incorporate the forms into it yourself. Here's the page.
Code:
http://www.boutell.com/newfaq/creating/scriptpass.html




Edit -
Here's an example using a form to collect the data if that make it easier for you.
Page1 sends the data to page2 via the url in the form of
- page2.html?boxvalue1=datastring1&boxvalue2=datastring2


This page gets the data input from your visitor and passes it to page2.html
- page1.html
Code:
<html>
<head>
<title>Pass form data to page2.html</title>
</head>

<body>
<p>Page 1 ~ Pass form data to page 2</p>
<form method="GET" 
      action="page2.html">
   Value One: <input type="text" name="boxvalue1" size="30">
   Value Two: <input type="text" name="boxvalue2" size="30">
   <input type="submit" value="Submit">
</form>

</body>
</html>


This page works if you just want to display the data from the page1.html somewhere.
- page2.html
Code:
<html>
<head>
<title>Recieve data from page1.html</title>

<script type="text/javascript">
     function getParams() {
       var idx = document.URL.indexOf('?');
       var params = new Array();
       if (idx != -1) {
         var pairs = document.URL.substring(idx+1, 
         document.URL.length).split('&');
         for (var i=0; i<pairs.length; i++) {
           nameVal = pairs[i].split('=');
           params[nameVal[0]] = nameVal[1];
         }
       }
       return params;
     }
 </script>

</head>

<body>
<p>Page 2 ~ Recieve data from page 1</p>
<script type="text/javascript">
    params = getParams();
    boxvalue1 = unescape(params["boxvalue1"]);
    boxvalue2 = unescape(params["boxvalue2"]);
    document.write("Value One = " + boxvalue1 + "<br>");
    document.write("Value Two = " + boxvalue2 + "<br>");
</script>

</body>
</html>

Alternate page2
This page works if you want to use the data from page1.html to prefill a form
- page2.html
Code:
<html>
<head>
<title>Prefill form with data from page1.html</title>

<script type="text/javascript">
  function FormPrefill() {
    var idx = location.href.indexOf('?');
    if(idx < 0) { return; }
    var pairs = location.href.substr(idx + 1).split('&');
    for(var i = 0; i < pairs.length; i++) {
       var nameVal = pairs[i].split('=');
       if(! eval('document.'+FormID+'.'+nameVal[0])) { continue; }
       eval('document.'+FormID+'.'+nameVal[0]+'.value="'+nameVal[1]+'"');
    }
  }
</script>
</head>

<body>
<p>Page 2 ~ Prefill form with data from page 1</p>
<form  method="POST" 
       action="http://whatever.com/targetpage.html"
       name="Form1">
     Value One: <input type="text" name="boxvalue1" size="30"><br>
     Value Two: <input type="text" name="boxvalue2" size="30"><br>
     Value Three: <input type="text" name="boxvalue3" size="30"><br>
     Value Four: <input type="text" name="boxvalue4" size="30"><br>
     <input type="submit" value="Submit"></td>
</form>

<script type="text/javascript">
     FormID = "Form1";
     FormPrefill();
</script>

</body>
</html>

Hope that helps. ~Wolf
 
Last edited:
Back
Top