You are here: Re: Two forms « PHP Programming Language « IT news, forums, messages
Re: Two forms

Posted by Rik on 10/18/06 00:08

Shelly wrote:
> It didn't work. Several things:
> 1 - I had the target for Aform be _self and for Bform be _blank since
> it is in A form with the _self that the list exists.
> 1 - The action path is "", even though you said you put one in. I
> left it that way.
> 2 - I assume you meant document.Bform.submit(); and not
> document.Aform.submit();
> 3 - If I made the change to Bform (above), then it opened a new window
> (according to Bform), but it didn't pass the value of theList, even
> though I have the B button in A form, and the page that is brought up
> in that new window is the current page, not the redirected one.
> Aform works fine. 4 - If I left it at Aform, it doesn't work either.
>
> Here is the code:
> junk.php
> ======
> <?php
> if (isset($_POST['A'])) {
> $val = $_POST['theList'];
> echo "A0=" . $val . "<br>";
> } else if (isset($_POST['B'])) {
> $val = $_POST['theList'];
> header("Location: junk2.php?val=" . $val);
> exit();
> }

Well, first of all:
1. Allthough AJAX is a nice buzzword, this has nothing to do with
(a)synchronous calls with javascript to the server.
2. Are you absolutely sure you want to rely on javascript for this? In some
browsers/for some users it will simply not work.
3. This should actually be in comp.lang.javascript

But here you go:
What I'd do, is have the buttons in the SAME form. Either that, or
duplicate the selection list if you want a sturdy application.

junk.php
<?php

if(isset($_POST['B']||isset($_POST['A'])){
if(isset($_POST['B'])) echo 'You choose to open this a new window, but
this is not possible without javascript enabled';
$val = $_POST['theList'];
echo "A0=" . $val . "<br>";
}
?>
<script type="text/javascript">
function form_new_window(button){
var form = button.form;
form.action = './junk2.php';
form.method = 'GET'; //or keep it a post
form.target = '_blank'; //new window
return true; //just to make sure.
}
</script>
<form action="./junk.php" method="POST" target="_self">
<select name="theList">
<option value="First'">First </option>
<option value="Second'">Second </option>
</select>
<input type="submit" value="Same window" name="A">
<input type="submit" value="New window" name="B"
onclick="form_new_window(this)">
</form>

--
Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация