473,606 Members | 2,825 Online
Bytes | Software Development & Data Engineering Community
+ 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 1260
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
2111
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> <body> <script language="javascript"> <!-- var temp = new Array(2) var status = new Array();
4
4102
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 the NO radio button, once I do that it will not work. Any help would be greatly appreciated. Mitch
4
11027
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 to: if one is clicked, its corresponding information will become available on another document, if it's not clicked no information will be provided. If multiple buttons are clicked their information will available on the same document. I'm not...
0
1959
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 confirm message box, if user click on the 'cancel' button, system will programatically check the previous radio button instead of the latest radio button that checked.
3
3117
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, the text will change to lowercase. I added the following event, but still won't able to change the text to uppercase. Private Sub RadioButton1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles...
0
1800
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 conversion). When the user enters a text in >text field, the user can click the radio button for case conversion. I set >the property of radio button to AutoPostBack=True, the
2
2296
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 add that it behaves fine in Firefox, but IE is unable to re-enable the radio button. IE is fine if the radio button starts in an enabled state.
1
3216
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 button with this link of code: echo 'SCRIPT language=JavaScript setCheckedValue("'.$_SESSION.'");</SCRIPT>'; //? <snip of code>
10
6069
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 button with this link of code: echo 'SCRIPT language=JavaScript setCheckedValue("'.$_SESSION.'");</SCRIPT>'; //? <snip of code>
2
1706
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 selected. And radio 2 - disabled, radio 4 - normal when radio 3 is selected (i.e. vice versa). My main question here is how do i get to know the state(i.e. normal or disabled) of a radio button as a feedback? thanx in advance
0
7981
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8467
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8320
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6803
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5994
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5470
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3952
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2458
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1574
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.