VK wrote:
Quote:
IchBin wrote:
Quote:
>I am trying to set the state of a radio button. I do not see what I am
>doing wrong.
>
PHP is executed server-side; JavaScript is executed client-side. That
would be most helpful:
1) To know what exactly "wrong" in your case (radio button states do
not change; they change but on wrong buttons; browser crashes;
something else)
2) To see the page as it is at the moment of the JavaScript code
execution (thus served from the server to the user-agent). For this
generate HTML output out of your PHP (<http>...</http>) and post it
here.
>
Sorry all works, app wise, it is just the radio buttons do not stay
selected after selecting one once coming back from the server.. I do
post the button that is changed (Have echo'ed that value so I know I
trapped it, and trying to reset to that selected button.
The actual running code is here:
http://ichbin.9999mb.com
Not sure how I can trap the the generated HTML code coming back from the
server..
Here is the entire script:
<?php
/**
*
http://localhost/quotes/quotesCss.ph...RT=tswebeditor
*
* @version $Id$
* @copyright 2006 weconsultants,
http://weconsultants.phpnet.us
*/
session_start();
if(!isset($_SESSION['abbr_letter'])) {
$_SESSION['abbr_letter'] = 'A';
// echo 'setCheckedValue("abbr_letter",
"'.$_SESSION['abbr_letter'].'")';
}
require_once 'includes/config.inc.php';
require_once 'includes/header.inc.php';
if (xdebug_is_enabled())
echo "enable";
else
xdebug_enable();
//
// Start a Form
?>
<HTML>
<HEAD>
<link href="quotesCss.css" rel="stylesheet" type="text/css">
<SCRIPT TYPE="text/javascript">
<!--
// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(newValue) {
var len = document.author_abbrv.abbr_letter.length
for(var i = 0; i < len; i++)
{
document.author_abbrv.abbr_letter[i].checked = false;
if(document.author_abbrv.abbr_letter[i].value ==
newValue.toString())
{
document.author_abbrv.abbr_letter[i].checked = true;
}
}
}
-->
</SCRIPT>
</HEAD>
<b><FORM NAME="author_abbrv" method="POST" action="<?php echo
$_SERVER['PHP_SELF'];?>"></b>
<table>
<tr>
<td><input type="radio" name="abbr_letter" value="A"
onclick="submit()"A </td>
<td><input type="radio" name="abbr_letter" value="B"
onclick="submit()"B </td>
<td><input type="radio" name="abbr_letter" value="C"
onclick="submit()"C </td>
<td><input type="radio" name="abbr_letter" value="D"
onclick="submit()"D </td>
<td><input type="radio" name="abbr_letter" value="E"
onclick="submit()"E </td>
<td><input type="radio" name="abbr_letter" value="F"
onclick="submit()"F </td>
<td><input type="radio" name="abbr_letter" value="G"
onclick="submit()"G </td>
<td><input type="radio" name="abbr_letter" value="H"
onclick="submit()"H </td>
<td><input type="radio" name="abbr_letter" value="I"
onclick="submit()"I </td>
<td><input type="radio" name="abbr_letter" value="J"
onclick="submit()"J </td>
<td><input type="radio" name="abbr_letter" value="K"
onclick="submit()"K </td>
<td><input type="radio" name="abbr_letter" value="L"
onclick="submit()"L </td>
<td><input type="radio" name="abbr_letter" value="M"
onclick="submit()"M </td>
</tr>
<tr>
<td><input type="radio" name="abbr_letter" value="N"
onclick="submit()"N </td>
<td><input type="radio" name="abbr_letter" value="O"
onclick="submit()"O </td>
<td><input type="radio" name="abbr_letter" value="P"
onclick="submit()"P </td>
<td><input type="radio" name="abbr_letter" value="Q"
onclick="submit()"Q </td>
<td><input type="radio" name="abbr_letter" value="R"
onclick="submit()"R </td>
<td><input type="radio" name="abbr_letter" value="S"
onclick="submit()"S </td>
<td><input type="radio" name="abbr_letter" value="T"
onclick="submit()"T </td>
<td><input type="radio" name="abbr_letter" value="U"
onclick="submit()"U </td>
<td><input type="radio" name="abbr_letter" value="V"
onclick="submit()"V </td>
<td><input type="radio" name="abbr_letter" value="W"
onclick="submit()"W </td>
<td><input type="radio" name="abbr_letter" value="X"
onclick="submit()"X </td>
<td><input type="radio" name="abbr_letter" value="Y"
onclick="submit()"Y </td>
<td><input type="radio" name="abbr_letter" value="Z"
onclick="submit()"Z </td>
</tr>
</TABLE>
</FORM>
<b><FORM NAME="author" method="POST" action="<?php echo
$_SERVER['PHP_SELF'];?>"></b>
<SELECT NAME="author_pk" SIZE="20" COLS="10" onclick="submit()">
<?php
//
//Check for the first time pass
if( !isset($_POST['abbr_letter']) ) {
$_POST['abbr_letter'] = $_SESSION['abbr_letter'];
}
//
//Store the lastest selected option to the Session var
$_SESSION['abbr_letter'] = $_POST['abbr_letter'];
echo 'SCRIPT language=JavaScript
setCheckedValue("'.$_SESSION['abbr_letter'].'");</SCRIPT>'; //?
//
//Setup for the database call for authors by first letter
$sqlcmd = $author_detail_select_by_Letter . $_POST['abbr_letter']
. $author_detail_orderBy;
if ($result = mysql_query($sqlcmd))
{
while ($row = mysql_fetch_object($result))
{
printf("<option value='%d'>%s %s, %s %s %s</option>n",
$row->id, $row->TITLE, $row->lastname,
$row->firstname, $row->middlename, $row->SUFFIX);
}
mysql_free_result($result);
}
else
{
die('Database Error: ' . $mysql->error);
exit;
}
?>
</SELECT>
<?php
//
// Add the list of top 20 authors
require_once 'top20.php';
?>
</FORM>
<BODY>
<?php
//
// This form uses the POST method, so process any post selections here
if( isset($_POST['author_pk']) )
{
//
// Log what author the user is looking for to the DB
include 'quoteLogging.php';
//
// Get all of the Quotes associated with this author
$sqlcmd = $author_detail_select . $_POST['author_pk'];
if ($author_detail = mysql_query($sqlcmd))
{
while( $row = mysql_fetch_object($author_detail) )
{
printf('<span style="font-weight: bold;">%s %s, %s %s
%s </span>' .
' %s <br<div style="margin-left: 80px;">%s '.
'<span style="font-weight: bold;"></div><br>'.
'<div style="margin-left: 80px;"><span
style="font-weight: bold;">' .
" Link: </span><a href='%s'Authors detail
information</a></span></div><br>",
$row->TITLE, $row->lastname,
$row->firstname, $row->middlename, $row->SUFFIX,
$row->BIRTHDEATH,$row->DESCRIPTION,$row->LINK);
}
}
else
{
die('Database Error: ' . mysql_error());
exit;
}
//
// Select the number of Quotes the selected author has.
$sqlcmd = $author_quote_number . $_POST['author_pk'];
if ($numberOfQuotes = mysql_query($sqlcmd))
{
$row = mysql_fetch_object($numberOfQuotes);
printf( '<div style="margin-left: 80px;"><span
style="font-weight: bold;">'.
'Number of Quotes: </span%s<br>',
number_format($row->COUNT) .
' </div>');
}
else
{
die('Database Error: ' . mysql_error());
exit;
}
//
//
$sqlcmd = $author_quote_select . $_POST['author_pk'] . " ORDER
BY quote;";
if ($resultSet = mysql_query($sqlcmd))
{
while( $row = mysql_fetch_object($resultSet))
{
printf('<span style="font-weight:
bold;background-color: white;">Quote:</span%s<br>',
$row->QUOTE);
if ($row->QUOTELITREF != '' )
{
printf( '<span style="font-weight: bold;
background-color: white;">'.
'Quote Reference:</span%s<br><br>',
$row->QUOTELITREF);
}
else
{
print('<br>');
}
}
}
else
{
mysql_free_result($result);
die('Database Error==' . mysql_error());
exit;
}
}
//
// Add a footer for all to know
require_once 'includes/footer.inc.php';
//
// Close DB
include 'includes/closedb.inc.php';
?>
--
Thanks in Advance...
http://ichbin.9999mb.com
IchBin, Pocono Lake, Pa, USA
http://weconsultants.phpnet.us
__________________________________________________ ____________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)