galvin Posted December 13, 2009 Share Posted December 13, 2009 Not sure if the problem is with my PHP or Javascript, so I'm starting in this forum. I think I've included all relevant code below. The gist is that when this page loads, it grabs some info from the database and depending on one piece of info ('step'), a particular radio button is marked as "CHECKED" so that it is defaulted to being selected when viewed in the browser. Also, on pageload, some javascript chooses the proper radio button group to show. Anyway, the only problem is that the word "CHECKED" is properly being put into the right radio button, but in the browser, the button is NOT selected. It's weird because I view the SOURCE and the word "CHECKED" is right where it's supposed to be, but it's not showing as checked in the browser. I gotta think it might have something to do with the javascript that chooses which group to show, but I really don't know. If anyone has any ideas, please let me know... <?php require_once("includes/session.php"); require_once("includes/connection.php"); require_once("includes/functions.php"); include_once("includes/form_functions.php"); if (isset($_GET['conversionid'])) { $convid = $_GET['conversionid']; $sql = "SELECT * FROM conversions WHERE conversionid = $convid"; $getconvinfo = mysql_query($sql, $connection); if (!$getconvinfo) { die("Database query failed: " . mysql_error()); } else { $convinfo = mysql_fetch_array($getconvinfo); $_SESSION['state'] = $convinfo['state']; $currentlevel = $convinfo['level']; $currentstep = $convinfo['step']; } } else { redirect_to('index.php'); } if ($currentlevel == "Standard") { $level = 1; } elseif ($currentlevel == "Advanced") { $level = 2; } elseif ($currentlevel == "Premium") { $level = 3; } elseif ($currentlevel == "") { $level = 4; } elseif ($currentlevel == "") { $level = 5; } else { $level = 6; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <link href="stylesheets/tracker.css" media="all" rel="stylesheet" type="text/css" /> <script type="text/javascript"> var disStyle=0 var dom=document.getElementById||document.all function getItem(id) { return document.getElementById&&document.getElementById(id)? document.getElementById(id) : document.all&&document.all[id]? document.all[id] : null; } if(dom) document.write('<style type="text/css" id="dummy">\ .tlink{\ display:none;\ }\ <\/style>') if(dom&&typeof getItem('dummy').disabled=='boolean'){ document.write('<style type="text/css" id="showhide">\ .showhide{\ display:none;\ }\ #cdiv0 {\ display:block;\ }\ <\/style>'); disStyle=1; } function displayOne(idPrefix, idNum){ var i=0; while (getItem(idPrefix+i)!==null){ getItem(idPrefix+i).style.display='none'; i++; } if (typeof idNum!=='undefined') getItem(idPrefix+idNum).style.display=''; } onload=function(){ displayOne('cdiv', <?php echo $level;?>); if (disStyle) getItem('showhide').disabled=true; } </script> </head> <body> <div id="entirepage"> <?php echo "convinfo=" . $convinfo['state']; require_once("includes/header.php"); $states_arr = array('AL'=>"Alabama",'AK'=>"Alaska",'AZ'=>"Arizona",'AR'=>"Arkansas",'CA'=>"California",'CO'=>"Colorado",'CT'=>"Connecticut",'DE'=>"Delaware",'DC'=>"D.C.",'FL'=>"Florida",'GA'=>"Georgia",'HI'=>"Hawaii",'ID'=>"Idaho",'IL'=>"Illinois", 'IN'=>"Indiana", 'IA'=>"Iowa", 'KS'=>"Kansas",'KY'=>"Kentucky",'LA'=>"Louisiana",'ME'=>"Maine",'MD'=>"Maryland", 'MA'=>"Massachusetts",'MI'=>"Michigan",'MN'=>"Minnesota",'MS'=>"Mississippi",'MO'=>"Missouri",'MT'=>"Montana",'NE'=>"Nebraska",'NV'=>"Nevada",'NH'=>"New Hampshire",'NJ'=>"New Jersey",'NM'=>"New Mexico",'NY'=>"New York",'NC'=>"North Carolina",'ND'=>"North Dakota",'OH'=>"Ohio",'OK'=>"Oklahoma", 'OR'=>"Oregon",'PA'=>"Pennsylvania",'RI'=>"Rhode Island",'SC'=>"South Carolina",'SD'=>"South Dakota",'TN'=>"Tennessee",'TX'=>"Texas",'UT'=>"Utah",'VT'=>"Vermont",'VA'=>"Virginia",'WA'=>"Washington",'WV'=>"West Virginia",'WI'=>"Wisconsin",'WY'=>"Wyoming"); function showOptionsDrop($array){ $string = ''; foreach($array as $k => $v){ if ($k == $_SESSION['state']) { $string .= '<option value="'.$k.'" selected="selected">'.$v.'</option>'."\n"; } else { $string .= '<option value="'.$k.'">'.$v.'</option>'."\n"; } } return $string; } ?> <div id=""> Edit Conversion info below... <table> <form action="updateconversion.php?conversionid=<?php echo $convid;?>" method="post"> <div id="container"> <tr class="showhide" id="cdiv0" name="cdiv0"><tr> <td> Choose the current step for this Conversion: </td> </tr> <?php if ($currentstep == "0") { $chosenstep0='CHECKED'; } else { $chosenstep0=""; } if ($currentstep == "1") { $chosenstep1='CHECKED'; } else { $chosenstep1=""; } if ($currentstep == "2") { $chosenstep2='CHECKED'; } else { $chosenstep2=""; } if ($currentstep == "3") { $chosenstep3='CHECKED'; } else { $chosenstep3=""; } if ($currentstep == "4") { $chosenstep4='CHECKED'; } else { $chosenstep4=""; } ?> <tr class="showhide" id="cdiv1" name="cdiv1"> <td> <INPUT TYPE="RADIO" NAME="step" VALUE="0" <?php echo $chosenstep0; ?>>Just assigned<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="1" <?php echo $chosenstep1; ?>>Intro Call Made/Info Sent<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="2" <?php echo $chosenstep2; ?>>Test Data Received and Confirmed (if applicable)<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="3" <?php echo $chosenstep3; ?>>Live!<BR> </td> </tr> <tr class="showhide" id="cdiv2" name="cdiv2"><td> <INPUT TYPE="RADIO" NAME="step" VALUE="0" <?php echo $chosenstep0; ?>>Just assigned<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="1" <?php echo $chosenstep1; ?>>Intro Call Made/Info Sent<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="2" <?php echo $chosenstep2; ?>>Draft Data Received<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="3" <?php echo $chosenstep3; ?>>Draft Completed<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="4" <?php echo $chosenstep4; ?>>Live!<BR> </td></tr> <tr class="showhide" id="cdiv3" name="cdiv3"><td> <INPUT TYPE="RADIO" NAME="step" VALUE="0" <?php echo $chosenstep0; ?>>Just assigned<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="1" <?php echo $chosenstep1; ?>>Intro Call Made/Info Sent<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="2" <?php echo $chosenstep2; ?>>Draft Data Received<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="3" <?php echo $chosenstep3; ?>>Draft Completed<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="4">Live!<BR></td></tr> <tr class="showhide" id="cdiv4" name="cdiv4"><td> <INPUT TYPE="RADIO" NAME="step" VALUE="0" <?php echo $chosenstep0; ?>>Just assigned<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="1" <?php echo $chosenstep1; ?>>Intro Call Made/Info Sent<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="2" <?php echo $chosenstep2; ?>>Test Data Received and Confirmed (if applicable)<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="3" <?php echo $chosenstep3; ?>>Live! </td></tr> <tr class="showhide" id="cdiv5" name="cdiv5"><td> <INPUT TYPE="RADIO" NAME="step" VALUE="0" <?php echo $chosenstep0; ?>>Just assigned<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="1" <?php echo $chosenstep1; ?>>Intro Call Made/Info Sent<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="2" <?php echo $chosenstep2; ?>>Confirmed/Scheduled with MC<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="3" <?php echo $chosenstep3; ?>>Live! </td></tr> <tr class="showhide" id="cdiv6" name="cdiv6"><td> <INPUT TYPE="RADIO" NAME="step" VALUE="0" <?php echo $chosenstep0; ?>>Just assigned<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="1" <?php echo $chosenstep1; ?>>Intro Call Made/Info Sent<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="2" <?php echo $chosenstep2; ?>>Transfer Scheduled with PR<BR> <INPUT TYPE="RADIO" NAME="step" VALUE="3" <?php echo $chosenstep3; ?>>Live! </td></tr> </div> Quote Link to comment https://forums.phpfreaks.com/topic/184938-radio-button-showing-as-checked-in-the-source-code-but-not-checked-in-browser/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 13, 2009 Share Posted December 13, 2009 The correct syntax for a radio button is - checked="checked" Quote Link to comment https://forums.phpfreaks.com/topic/184938-radio-button-showing-as-checked-in-the-source-code-but-not-checked-in-browser/#findComment-976289 Share on other sites More sharing options...
galvin Posted December 13, 2009 Author Share Posted December 13, 2009 Tried that too and it doesn't work either I view the source code and it shows checked="checked" properly, yet the button isn't checked when viewed in the browser. This is driving me nuts, seems like such a simple thing Any other ideas, let me know... Thanks, Greg Quote Link to comment https://forums.phpfreaks.com/topic/184938-radio-button-showing-as-checked-in-the-source-code-but-not-checked-in-browser/#findComment-976293 Share on other sites More sharing options...
GFXUniverse Posted December 13, 2009 Share Posted December 13, 2009 (may b i didn't get u clearly but after having a look at inputs code i found this) all radio inputs steps have same names why r they repeating? use the code this way <tr class="showhide" id="cdiv1" name="cdiv1"> <td> <INPUT TYPE="RADIO" NAME="step0" VALUE="0" <?php echo $chosenstep0; ?>>Just assigned<BR> <INPUT TYPE="RADIO" NAME="step1" VALUE="1" <?php echo $chosenstep1; ?>>Intro Call Made/Info Sent<BR> <INPUT TYPE="RADIO" NAME="step2" VALUE="2" <?php echo $chosenstep2; ?>>Test Data Received and Confirmed (if applicable)<BR> <INPUT TYPE="RADIO" NAME="step3" VALUE="3" <?php echo $chosenstep3; ?>>Live!<BR> </td> </tr> ... examlpe you check a radio then u check second radio option, if this second radio have same name so first radio will be unchecked. use different names Quote Link to comment https://forums.phpfreaks.com/topic/184938-radio-button-showing-as-checked-in-the-source-code-but-not-checked-in-browser/#findComment-976310 Share on other sites More sharing options...
galvin Posted December 13, 2009 Author Share Posted December 13, 2009 The names have to be the same. You have the same name for all radio buttons within the same grouping. Than NAME stays the same, the VALUEs change. Quote Link to comment https://forums.phpfreaks.com/topic/184938-radio-button-showing-as-checked-in-the-source-code-but-not-checked-in-browser/#findComment-976324 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.