PDA

View Full Version : Display form result in iframe on different page



ing.kudykam
01-29-2010, 12:52 PM
Hi,
i will try to be as brief as possible.
I have a page A with form:


<form id="search" action="find.html" method="get">
... (some select options) ...
<input type="submit" class="submit" value="search">

this form look up some holiday destination which appears on this page with url:
(example)

www.domain.com/find.html?destination=italy&price=500

Now, I dont want to display result on this page, but on page B, in iframe.
I found a way how to redirect output as a link to properly show in iframe on page B.

Page A contains:

<a href="pageb.html?http://www.domain.com/find.html?destination=italy&price=500">show on page B</a><br>

Page B contains:



<script type="text/javascript">
<!--

function loadIframe(){
if (location.search.length > 0){
url = unescape(location.search.substring(1))

window.frames["iframe"].location=url
}
}

onload=loadIframe
//-->
</script>

<iframe src="" name="iframe" id="iframe"</iframe>

In this case page B will properly load requested link in iframe.
Problem is it is just a static link...

I want to display search result from the form.

Thanks a lot for your help...

gusblake
01-29-2010, 04:40 PM
It would be better to use a function like the following to get each URL parameter



function gup(name) {
name=name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS="[\\?&]"+name+"=([^&#]*)";
var regex=new RegExp(regexS);
var results=regex.exec(window.location.href);
if(results==null) return "";
else return results[1];
}


then set the form method to GET and give each option its own field:



<form action="pageB.html" method="GET">
<input name="url" type="text">
<input name="destination" type="text">
<input name="price" type="text">
<input type="submit" value="Submit">
</form>


and construct the iframe URL on page B like this



function loadIframe(){
if (location.search.length > 0) {
var site=gup("url");
var dest=gup("destination");
var cost=gup("price");
var url=site+"?"+"destination="+dest+"&price="+cost;
window.frames["iframe"].location=url;
}
}

ing.kudykam
01-29-2010, 09:38 PM
Thanks for your answer gusblake
It seems like it could work but...
It should show this address in adress bar to work properly:

http://www.czech-paradise.cz/testb.html?http://www.zajezdy.czech-paradise.cz/hledej.html?zeme=&termin=&cena=&delka=

(note 2 question marks)

but it shows this:

http://www.czech-paradise.cz/testb.html?url=http%3A%2F%2Fwww.zajezdy.czech-paradise.cz%2Fhledej.html&zeme=&termin=&cena=&delka=
which is wrong.

My code is now, for page A:

<form id="hledej" action="testb.html" method="get">
<input name="url" type="text" value="http://www.zajezdy.czech-paradise.cz/hledej.html" style="display:none" />
<select id="zeme" name="zeme">
...
...
<input type="submit" class="submit" value="Hledej"/>
</form>

Page B:

<body>
<script type="text/javascript">
<!--
function gup(name) {
name=name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS="[\\?&]"+name+"=([^&#]*)";
var regex=new RegExp(regexS);
var results=regex.exec(window.location.href);
if(results==null) return "";
else return results[1];
}
function loadIframe(){
if (location.search.length > 0) {
var site=gup("url");
var dest=gup("zeme");
var cost=gup("termin");
var cost=gup("cena");
var cost=gup("delka");
var url=site+"?"+"zeme="+zeme+"&termin="+termin+"&cena="+cena+"&delka="+delka;
window.frames["fr_zajezdy"].location=url;
}
}
onload=loadIframe
//-->
</script>
<iframe src="" name="fr_zajezdy" id="fr_zajezdy"> </iframe>
</body>

Any idea how to fix it?

gusblake
01-30-2010, 06:43 PM
Each of the variables you use to construct the URL for the iframe need to be assigned by calls to gup:



var site=gup("url");
var zeme=gup("zeme");
var termin=gup("termin");
var cena=gup("cena");
var delka=gup("delka");


But if the url (site) will always be the same, you could just do this:

A:



<form id="hledej" action="testb.html" method="get">
<select id="zeme" name="zeme">
...
<input type="submit" class="submit" value="Hledej"/>
</form>


B:



<body>
<script type="text/javascript">
function loadIframe(){
if (location.search.length > 0) {
window.frames["fr_zajezdy"].location="http://www.zajezdy.czech-paradise.cz/hledej.html"+location.search;
}
}

onload=loadIframe
</script>
<iframe src="" name="fr_zajezdy" id="fr_zajezdy"> </iframe>
</body>

crosswire
02-09-2010, 03:15 AM
I created a book library which im testing and results show up fine in joomla and the included template.

Now I want to incorporate the search and the results ie the part that says


into my orgs website.I couldn't install joomla on my work site since they dont support mysql so had to do it externally.

I managed to get the search box in lib.html which is on work site which is the above link but when it shows the results it opens up my other website in joomla.
I would rather just show the results in one page and not the other site and without the joomla template on work site.

any ideas and advice.
thanks

see here for result page part


any advice pls

tatik
10-06-2011, 05:57 PM
I'm searching for this code or concept that can help me in displaying results of a mini search engine on the same page (into an iframe).

Did crosswire succeeded finally?

Anyone?

Carol

Old Pedant
10-06-2011, 09:43 PM
Don't hijack old threads.

Start your own new thread.

Repost this question in a new thread but give more details. Such as what language/system the mini search engine is written in (that is, is it PHP? Or is it all HTML/Javascript?).

Also, your question is much much simpler than the one in this thread. It's trivial to work with iframes in the same window/page. This thread was about working with iframes in another window.