Jump to content


Photo

submit button and iframe


  • Please log in to reply
6 replies to this topic

#1 shumbora

shumbora
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 01 May 2006 - 07:23 PM

hello evrey one, i was hopeing to build a search engine on my site that would search other sites like yahoo , google ,ect.. i've been having one problem with it tho , im trying to get the search results to open in an iframe but all my efforts do this have been in vain , i should mention that im a noob at this , that siad here is the code
this is my .js file (test.js)
function doSearch( selectedIndex, searchTerm ) {
   if ( selectedIndex < 0 ) {
      alert("Please select a search engine!");
      return false;
   } else if ( searchTerm == "" ) {
      alert("No search term!");
      return false;
   }
   window.open( SEARCH_DATA[selectedIndex][1] , SEARCH_DATA[selectedIndex][0] );
}



function engine1( selectedIndex, searchTerm ) 
{
   SEARCH_DATA= new Array(73);
   <!--SEARCH_DATA[value]= new Array( window name , url ) -->
   SEARCH_DATA[1]= new Array("yahoo","http://search.yahoo.com/search?p="+escape(searchTerm)+"&sm=Yahoo%21+Search&fr=FP-tab-web-t&toggle=1&cop=&ei=UTF-8");

    
doSearch( selectedIndex, searchTerm );
   return true;
}
this is the form code
<script language=JavaScript src="test.js" type=text/javascript></script>
<div align="center"> 
<form name="searchForm1" action="" onSubmit="javascript:engine1(this.engine.options[this.engine.selectedIndex].value,this.go.value); return false;">
<select name="engine" class="drop_down">
<option value="-1" selected>Torrent Search</option>
<option value="1">yahoo</option>

</select>
<input name="go" class="text_field" size="20" maxlength="35" />
<input name="submit" type="submit" class="search_button" value="Search" />
</form>
this is my iframe statment
<iframe id="inpage"  style="width:600px;height:400px" src="http://www.google.com"></iframe>
im trying to set it up so that when the search button is clicked it would open the search results in the iframe. any comments will be appreciated and thanx in advance:D

#2 onepixel

onepixel
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 02 May 2006 - 02:59 AM

I suggest you use this line of Javascript code:
document.inpage.open( SEARCH_DATA[selectedIndex][1] , SEARCH_DATA[selectedIndex][0] );


<a href="http://www.saheltech.com">PHP Programming - WordPress Blog Customization</a>

#3 shumbora

shumbora
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 02 May 2006 - 04:43 AM

thank you for tryin but it didnt really work

#4 GBS

GBS
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 02 May 2006 - 08:25 AM

Hi there,,

That one should works,, tested with IE & FF,,
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>testing,,</title>
</head>
<body>
<script>
function doSearch( selectedIndex, searchTerm ) {
   if ( selectedIndex < 0 ) {
      alert("Please select a search engine!");
      return false;
   } else if ( searchTerm == "" ) {
      alert("No search term!");
      return false;
   }
DoTheSearchInTheFrame(SEARCH_DATA[selectedIndex][1], SEARCH_DATA[selectedIndex][0]);
}

function engine1( selectedIndex, searchTerm )
{
   SEARCH_DATA= new Array(73);
   <!--SEARCH_DATA[value]= new Array( window name , url ) -->
   SEARCH_DATA[1]= new Array("google","http://www.google.fr/search?hl=fr&q="+escape(searchTerm)+"&btnG=Recherche+Google&meta=");
   SEARCH_DATA[2]= new Array("yahoo","http://search.yahoo.com/search?p="+escape(searchTerm)+"&sm=Yahoo%21+Search&fr=FP-tab-web-t&toggle=1&cop=&ei=UTF-8");

doSearch( selectedIndex, searchTerm );
   return true;
}

function DoTheSearchInTheFrame(var_a,var_b)
{
eval("document.getElementById('inpage').src=var_a");
}

</script>

<div align="center">
<form name="searchForm1" action="" onSubmit="javascript:engine1(this.engine.options[this.engine.selectedIndex].value,this.go.value); return false;">
<select name="engine" class="drop_down">
<option value="-1" selected>Select a search engine</option>
<option value="1" >Google</option>
<option value="2">yahoo</option>
</select>
<input name="go" class="text_field" size="20" maxlength="35" />
<input name="submit" type="submit" class="search_button" value="Search" />
</form>
</div>

<iframe id="inpage"  style="width:600px;height:400px" src="http://www.google.com"></iframe>

</body>
</html>
The important line is:
eval("document.getElementById('inpage').src=var_a");, which changes the content of the iframe,,

Hoping it helps,,

l8tr,,
Sorry for my english,... I do my best, but sometimes,...
1st intention: understand the problem
2nd intention: try to solve it
3rd intention: try to understand how to solve it :)

#5 shumbora

shumbora
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 02 May 2006 - 08:20 PM

firest off i just wanna say that you ROCK , your scrpit worked flawlessly , but i have a question , how do i manipulate it so that it would use the search data from the .js file insted of embedding all of the search data right into the html, because i plane to add many more search engines. and thanx again for your help

#6 GBS

GBS
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 03 May 2006 - 08:13 AM

cool, nice to hear, & glad to have helped you there,,
about your question, the manipulation to do is quiet easy,,
just split the code like this,
html part:
<html>
<head>
<title>testing,,</title>
</head>
<body>
<script language=JavaScript src="test.js" type=text/javascript></script>
<div align="center">
<form name="searchForm1" action="" onSubmit="javascript:engine1(this.engine.options[this.engine.selectedIndex].value,this.go.value); return false;">
<select name="engine" class="drop_down">
<option value="-1" selected>Select a search engine</option>
<option value="1" >Google</option>
<option value="2">yahoo</option>
</select>
<input name="go" class="text_field" size="20" maxlength="35" />
<input name="submit" type="submit" class="search_button" value="Search" />
</form>
</div>
<iframe id="inpage" style="width:600px;height:400px" src="http://www.google.com"></iframe>
</body>
</html>
& you can put in the test.js file the javascript functions,
function doSearch( selectedIndex, searchTerm ) {
   if ( selectedIndex < 0 ) {
      alert("Please select a search engine!");
      return false;
   } else if ( searchTerm == "" ) {
      alert("No search term!");
      return false;
   }
DoTheSearchInTheFrame(SEARCH_DATA[selectedIndex][1], SEARCH_DATA[selectedIndex][0]);
}

function engine1( selectedIndex, searchTerm )
{
   SEARCH_DATA= new Array(73);
   <!--SEARCH_DATA[value]= new Array( window name , url ) -->
   SEARCH_DATA[1]= new Array("google","http://www.google.fr/search?hl=fr&q="+escape(searchTerm)+"&btnG=Recherche+Google&meta=");
   SEARCH_DATA[2]= new Array("yahoo","http://search.yahoo.com/search?p="+escape(searchTerm)+"&sm=Yahoo%21+Search&fr=FP-tab-web-t&toggle=1&cop=&ei=UTF-8");

doSearch( selectedIndex, searchTerm );
   return true;
}

function DoTheSearchInTheFrame(var_a,var_b)
{
eval("document.getElementById('inpage').src=var_a");
}
Hoping I get your question [still my english,... :) ] & it helps...

l8tr,,
Sorry for my english,... I do my best, but sometimes,...
1st intention: understand the problem
2nd intention: try to solve it
3rd intention: try to understand how to solve it :)

#7 shumbora

shumbora
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 03 May 2006 - 08:44 PM

hey thanx alot man you have no idea how much i appreciate your help , once again ur scrpit is flawless. and thanx again.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users