Wrox Programmer Forums
|
HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 25th, 2003, 09:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default Many Buttons on 1 form

I have made a form that has 2 dropdowns, I want to have a button for each of 4 different results pages that all use the selections from those dropdowns as criteria for queries, but I can't get any of them to work.

How do I write the post statements so that each button posts to a different page?

Below is what I have thus far, which opens the correct page, but that page always says no data was passed.

<!-- *** Works for just one page, remed for now***
<form method="post" action="goal_rankings_new.php">
-->

<select name="searchteam">
<?php
$query = mysql_query('select TeamID, TeamName, Nickname, TeamCity from PH_TEAMS') or die
(mysql_error());
while($row = mysql_fetch_array($query)) {
    echo("<option value=\"${row['TeamID']}\">

${row['TeamName']}, ${row['Nickname']}, ${row['TeamCity']}\n");
}
?>
</select>




<select name="searchseason">

<?php
$qSEASON = mysql_query('select SeasonID, SeasonName from PH_SEASON') or die
(mysql_error());
while($row2 = mysql_fetch_array($qSEASON)) {
    echo("<option value=\"${row2['SeasonID']}\">

${row2['SeasonName']}\n");
}
?>
</select>
<!-- **These are the buttons I want and the pages to send data to**
<FORM action="goal_rankings_new.php" method="POST">
<INPUT type=submit name="Goals" value=" Goals ">
</FORM>

<FORM action="penalties_rankings.php" method="POST">
<INPUT type=submit name="Penalties" value=" Penalties">
</FORM>

<FORM action="button3.php" method="POST">
<INPUT type=submit name="button3" value=" Button3 ">
</FORM>
__________________
Mitch
 
Old October 25th, 2003, 09:25 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Basically you need four standard buttons. In the only click of each have:
[code]
  doSubmit(this.form, 'target.htm');
[code]
Replace "target.htm" by the page to submit to. This is your doSubmit function:
Code:
function doSubmit(Form, Action)
{
  Form.action = Action;
  Form.submit();
}
--

Joe
 
Old October 25th, 2003, 10:56 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, but what is a "standard" button? Is it:
<input type="button" value="Button" name="B3">
 
Old October 25th, 2003, 11:21 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

Yep, end the 'only click' is onClick...

<input type="button" value="Button" name="B3" onClick="doSubmit(this.form, 'target.htm');">

 
Old October 25th, 2003, 11:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I see the function code on my page in the browser, do I need to enclose it in some sort of tag so it is not treated as text? Right now I have it in the header?
 
Old October 25th, 2003, 11:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

Yup:
Code:
<head>
<script language=javascript>
...
</script>
</head>
 
Old October 25th, 2003, 11:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thought so. Now the code is not showing up on the page.

But, I get a "error on page" when I click on it.

Here is where the page is: http://www.pennhockey.org/stats/test_buttons_2.php

Here is what I am using:

<HEAD>

<script language=javascript>

function doSubmit(Form, Action)
{
  Form.action = Action;
  Form.submit();
}
</SCRIPT>

<TITLE>PENN Hockey Club - Scoreing Leaders</TITLE>

<p align="center">
<?
include ("http://www.pennhockey.org/header.php");
?>


<h1 align="center">Select a Team to View Goal Rankings</h1>



<?
$connection = mysql_connect("xxxx", "xxxx", "xxxx");
$fields = mysql_list_fields("xxxx", "PH_PLAYERS", $connection);
?>

<!--
<form method="post" action="goal_rankings_new.php">
-->
<select name="searchteam">

<?php
$query = mysql_query('select TeamID, TeamName, Nickname, TeamCity from PH_TEAMS') or die
(mysql_error());
while($row = mysql_fetch_array($query)) {
    echo("<option value=\"${row['TeamID']}\">



${row['TeamName']}, ${row['Nickname']}, ${row['TeamCity']}\n");
}
?>
</select>




<select name="searchseason">

<?php
$qSEASON = mysql_query('select SeasonID, SeasonName from PH_SEASON') or die
(mysql_error());
while($row2 = mysql_fetch_array($qSEASON)) {
    echo("<option value=\"${row2['SeasonID']}\">



${row2['SeasonName']}\n");
}
?>
</select>



<input type="button" value="Goals" name="B3" onClick="doSubmit(this.form, 'goal_rankings_new.php');">

<input type="button" value="Penalties" name="B3" onClick="doSubmit(this.form, 'penalties_rankings.php');">


</form>


<p align="center">
 <?
 include ("http://www.pennhockey.org/footer.php");
 ?>
************************

Any ideas?
 
Old October 25th, 2003, 11:55 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

It seems to me that you have commented out the opening <form>-tag ?

 
Old October 25th, 2003, 12:03 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I went back to an older version and inserted the new stuff and it worked. I must have done just that.

Here is the code that worked:

<HEAD>

<script language=javascript>

function doSubmit(Form, Action)
{
  Form.action = Action;
  Form.submit();
}
</SCRIPT>

<TITLE>PENN Hockey Club - Stats</TITLE>

<p align="center">
<?
include ("http://www.pennhockey.org/header.php");
?>



<h1 align="center">Select a Team and Season to View Stats</h1>




<?
$connection = mysql_connect("xxxxx", "xxxx", "xxxxx");
$fields = mysql_list_fields("xxxxx", "PH_PLAYERS", $connection);
?>


<form method="post" action="goal_rankings_new.php">
<select name="searchteam">

<?php
$query = mysql_query('select TeamID, TeamName, Nickname, TeamCity from PH_TEAMS') or die
(mysql_error());
while($row = mysql_fetch_array($query)) {
    echo("<option value=\"${row['TeamID']}\">${row['TeamName']}, ${row['Nickname']}, ${row['TeamCity']}\n");
}
?>
</select>

<input type=submit value="Select">


<select name="searchseason">

<?php
$qSEASON = mysql_query('select SeasonID, SeasonName from PH_SEASON') or die
(mysql_error());
while($row2 = mysql_fetch_array($qSEASON)) {
    echo("<option value=\"${row2['SeasonID']}\">${row2['SeasonName']}\n");
}
?>
</select>

<input type=submit value="Select">



<input type="button" value="Goals" name="B3" onClick="doSubmit(this.form, 'goal_rankings_new.php');">

<input type="button" value="Penalties" name="B4" onClick="doSubmit(this.form, 'penalties_rankings.php');">



</form>


<p align="center">
 <?
 include ("http://www.pennhockey.org/footer.php");
 ?>
 
Old October 25th, 2003, 12:08 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks everyone for your help! Now my players can see their stats. (I'm a high school hockey coach, who just happens to like to program, albeit web programming is new to me.)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Referencing Command buttons on a form spiderman Access 1 September 6th, 2007 06:56 AM
Form Hint buttons help bucky483 XSLT 0 June 21st, 2007 01:12 AM
Form buttons Lofa Beginning PHP 1 March 12th, 2007 06:39 AM
One form.. two submit buttons ashraf_gawdat HTML Code Clinic 1 July 28th, 2006 06:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.