473,480 Members | 2,840 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

set previous state of radio button

2 New Member
i am not able to set the previous state of radio button in my test series which is being made in php. please help me out with some jquery code.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     session_start();
  3.     $qid = 0;
  4.     $total = 0;
  5.     if(isset($_SESSION["qids"]) && isset($_SESSION["ans"]))
  6.     {
  7.         $qids = $_SESSION["qids"];
  8.  
  9.         if(is_array($qids))
  10.         {
  11.         //    print_r($_SESSION["qids"]);            
  12.             $qid = $qids[0];
  13.         //    echo $qid;
  14.             $total = count($qids);
  15.         }
  16.     }
  17. ?>
  18.  
  19. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  20. <html xmlns="http://www.w3.org/1999/xhtml"><head>
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  22. <title>Untitled Document</title>
  23. <script type="text/javascript" src="jQuery.js">
  24. $('input:radio[name=theme]').click(function() {
  25.   var val = $('input:radio[name=theme]:checked').val();
  26. });
  27.   </script>
  28.  
  29.  
  30. <script type="text/javascript">
  31.  
  32.  
  33.     function next()
  34.     {
  35.         var qno = parseInt($("#qno").html());
  36.         var total = parseInt($("#total").html());
  37.         if((qno+1) < total )
  38.         {
  39.             var no = qno + 1;
  40.             var address = "getquestion.php?qno=" + no;
  41.             $.ajax({url:address,success:function(result){
  42.                 $("#questions").html(result);        
  43.                 $("#qno").html(no);
  44.             }});
  45.  
  46.         }
  47.         else
  48.         {
  49.             alert(" you are at Last Question ");
  50.         }
  51.  
  52.     }
  53.     function back()
  54.     { 
  55.  
  56.         var qno = parseInt($("#qno").html());
  57.         var total = parseInt($("#total").html());
  58.         if((qno-1) > 0 )
  59.         {
  60.             var no = qno - 1;
  61.             var address = "getquestion.php?qno=" + no;
  62.             $.ajax({url:address,success:function(result){
  63.             $("#questions").html(result);        
  64.             $("#qno").html(no);
  65.             }});
  66.  
  67.         }
  68.                 else
  69.                 {
  70.                 alert(" you are at First Question ");
  71.                 }
  72.     }
  73. </script>
  74. </head>
  75.  
  76. <body>
  77. <div id="questions">
  78. <form name="frmone">
  79. <table cellpadding="15" cellspacing="15" align="center" border="5" >
  80.  
  81.         <?php
  82.         $an  = isset($_GET["an"]) ? $_GET["an"] : "";
  83.  
  84.             include("dbcon.php");
  85.             $con = mysql_connect(SERVERNAME,USERNAME,PASSWORD);
  86.             if($con)
  87.             {
  88.                 mysql_select_db(DBNAME,$con);
  89.                 $query = "select questiontext,optiona,optionb,optionc,optiond from testquestion where questionid=$qid";
  90.                 echo $query;
  91.                 $result = mysql_query($query,$con) or die(mysql_error($con));
  92.                 if( $result && mysql_num_rows($result) > 0 )
  93.                 {
  94.                     while($row = mysql_fetch_array($result))
  95.                     {
  96.                         list($questiontext,$optiona,$optionb,$optionc,$optiond) = $row;
  97.  
  98.                         echo '<tr><th>' . $questiontext . '</th></tr>';
  99.  
  100.                         echo '<tr><td><input type="radio" id="radio" name="an" value="a"/>'.$optiona.'</td></tr>';
  101.                         echo '<tr><td><input type="radio" id="radio" name="an" value="b"/>'.$optionb.'</td></tr>';
  102.                         echo '<tr><td><input type="radio" id="radio" name="an" value="c"/>'.$optionc.'</td><tr>';
  103.                         echo '<tr><td><input type="radio" id="radio" name="an" value="d"/>'.$optiond.'</td></tr>';                                                                
  104.                         echo '</tr>';
  105.                     }
  106.                 }
  107.                 else
  108.                 {
  109.                     echo '<tr><td colspan="5" align="center">There is No Data</td></tr>';
  110.                 }
  111.  
  112.             }?>
  113.             </table>
  114.             </div>
  115.             <?php
  116.                 echo '<span id="qno" style="display:none">0</span>';
  117.                 echo '<span id="total" style="display:none">' . $total . '</span>';
  118.                 echo '<center><input type="button" onclick="back()"  value="BACK">    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';                                            
  119.                 echo '<input type="button" onclick="next()" value="NEXT"></center>';
  120.             ?>
  121. </form>
  122. </body>
  123. </html>
Jul 1 '14 #1
1 1248
Dormilich
8,658 Recognized Expert Moderator Expert
is this supposed to be a PHP problem or a JavaScript problem? you can’t fix a PHP issue with JavaScript or vice versa.

if it’s a JavaScript problem please post the according HTML code and not the PHP that generates it.
Jul 2 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

15
2094
by: tabonni | last post by:
I want to check each button groups and save the checked value into a 2 dimensional array. But, it doesn't work. Could anyone tell me what's wrong with my code. My code is as follow: <html>...
4
4082
by: mitch-co2 | last post by:
What I am trying to do is when someone clicks on the YES radio button I want the text field called MYTEXT to equal the text field named DATE. The below code works as long as I do NOT UN-COMMENT...
4
11020
by: Jared | last post by:
Radio Button or Check Box and Event Procedures I need to insert either radio buttons or check boxes onto my form. I'm not sure which to use, or if there are other options. I am using the buttons...
0
1943
by: hy | last post by:
Hi all, I got the question about the radio button. How do i detect previous checked radio button after i checked other's radio button. While the new radio button checked, it need to prompt out a...
3
3093
by: John Davis | last post by:
I created a ASP.NET Web Form using VB.NET with a text box, 2 radio buttons. When the user click the first radio button, the text will change to uppercase. If the user clicks the other radio button,...
0
1793
by: vinay | last post by:
why are u not using the radiobutton list??? vinay >-----Original Message----- >I created a simple ASP.NET application with a text field, and 2 radio >buttons (uppercase and lowercase...
2
2291
by: xazos79 | last post by:
Hi All, I've come across the problem of not being able to re-enable a radio button with javascript if its initial state has been disabled in the Page_Load() method of the code behind. Might i...
1
3207
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
10
6044
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
2
1696
by: vajratkarviraj | last post by:
Hi, Am using Tkinter. Suppose I have 4 radio buttons (value 1,2,3 & 4) arranged in a single column. I want radio 2 to have a normal state and radio 4 to have a disabled state when radio 1 is...
0
7055
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7060
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6760
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7022
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4501
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.