2011-03-03 13 views
1

フォームを送信して非表示のiFrameを同時にロードして、本質的に2つの事柄を引き起こすことができるようにしたい - 1. BingのAPIを使用して検索を実行する2.入力したテキストを取得する大声で読み上げる入力にフォームを送信して同時にiframeをロード

私は独立して動作していますが、同時に動作していません。

2つのフォームアクションを持つことができないので、送信ボタンでonclickを使って何かできるのですか?

これは私のコードですが、私は現時点で2つのフォームを持っています。ボタンを1つクリックして両方を実行する方法をいくつか組み合わせたいと思います。私は完全にこれを行う方法の他の提案にオープンです!

<html> 
<head> 
    <link href="styles.css" rel="stylesheet" type="text/css" /> 
<title>PHP Bing</title> 
</head> 
<body><form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> 
Enter Search:<input type="text" id="searchText" name="searchText" value="<?php 
if (isset($_POST['searchText'])){ 
    echo($_POST['searchText']); } 
else { 
echo(''); 
} ?>"/> 

<input type="submit" value="Search!" name="submit" id="searchButton" /> 
<?php 
if (isset($_POST['submit'])) { 

$request = 
'http://api.bing.net/json.aspx?Appid=8CFD0925A6B1745AFE2F0F359DCD8D4D9DD6A5CE&sources=web&Web.Count=5&query=' . urlencode($_POST["searchText"]);$response = file_get_contents($request); 
$jsonobj = json_decode($response); 
echo('<ul ID="resultList">');      

foreach($jsonobj->SearchResponse->Web->Results as $value) { 

echo('<li class="resultlistitem"><a href="' . $value->Url . '">'. $value->Title .'</a>'); 
echo('<p>'. $value->Description .'</p>'); 
echo('</li>'); 
} 
echo("</ul>"); 
} 
?> 
</form> 


<form method="post" action="http://vozme.com/text2voice.php" target="hiddeniframe"> 
<textarea id="text" cols="40" rows="1" name="text"> 
Enter Text 
</textarea><br> 
<button style="background-color:white; 
background-image: 
url(http://vozme.com/img/megaphone40x40w.gif); 
background-position: top center; 
background-repeat:no-repeat; 
height: 48px; font-size:70%; 
padding:4px 4px 4px 44px;"> 
</button> 
</form> 


<iframe height="1" width="1" name="hiddeniframe" style="display: none;"></iframe> 

</body> 
</html> 

答えて

1

JSのボタンクリックイベントを登録し、1)iframeを読み込み、2)フォームを送信する必要があります。 (あなたはそれを他の方法で回避しなかった場合は、トップページがアンロードされると、IFRAMEの負荷が中止される可能性があります)(簡潔にするためにjQueryを使用して)

簡体例:それは本当にだような偉大な、と思われることを

<form id="someform" action="/foo/bar" method="POST"> 
    <button id="yourbutton">should trigger two actions</button> 
</form> 
<iframe id="some_iframe"></iframe> 

<script> 
    $(document).ready(function(){ // register to run this when page is ready 
     $('#yourbutton').click(function(){ // register to run this when #yourbutton clicked 
      $('#some_iframe').load(function(){ // register to run this when #some_iframe loads 
       $('#someform').submit(); 
      }); 
      // and *then* load the iframe 
      $('#some_iframe').setAttribute('src','http://example.com/some/URL'); 
     }); 
    }); 
</script> 
+0

おかげで仕事に近い。 Bingの検索は動作していますが、それを送信したときには表示されません。1.別のiframeで目的のページが読み込まれています。2.読み込まれたiframeに同じデータを送信していません。 – user633075

+0

これはまだ動作しません、任意のアイデア? – user633075

関連する問題