set previous state of radio button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ruhani
    New Member
    • Jul 2014
    • 2

    set previous state of radio button

    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.
    Code:
    <?php
    	session_start();
    	$qid = 0;
    	$total = 0;
    	if(isset($_SESSION["qids"]) && isset($_SESSION["ans"]))
    	{
    		$qids = $_SESSION["qids"];
    		
    		if(is_array($qids))
    		{
    		//	print_r($_SESSION["qids"]);			
    			$qid = $qids[0];
    		//	echo $qid;
    			$total = count($qids);
    		}
    	}
    ?>
    
    <!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>Untitled Document</title>
    <script type="text/javascript" src="jQuery.js">
    $('input:radio[name=theme]').click(function() {
      var val = $('input:radio[name=theme]:checked').val();
    });
      </script>
    
    
    <script type="text/javascript">
    
    
    	function next()
    	{
    		var qno = parseInt($("#qno").html());
    		var total = parseInt($("#total").html());
    		if((qno+1) < total )
    		{
    			var no = qno + 1;
    			var address = "getquestion.php?qno=" + no;
    			$.ajax({url:address,success:function(result){
    				$("#questions").html(result);		
    				$("#qno").html(no);
    			}});
    			
    		}
    		else
    		{
    			alert(" you are at Last Question ");
    		}
    		
    	}
    	function back()
    	{ 
    	
    		var qno = parseInt($("#qno").html());
    		var total = parseInt($("#total").html());
    		if((qno-1) > 0 )
    		{
    			var no = qno - 1;
    			var address = "getquestion.php?qno=" + no;
    			$.ajax({url:address,success:function(result){
    			$("#questions").html(result);		
    			$("#qno").html(no);
    			}});
    			
    		}
    				else
    				{
    				alert(" you are at First Question ");
    				}
    	}
    </script>
    </head>
    
    <body>
    <div id="questions">
    <form name="frmone">
    <table cellpadding="15" cellspacing="15" align="center" border="5" >
        	
            <?php
    		$an  = isset($_GET["an"]) ? $_GET["an"] : "";
    		
    			include("dbcon.php");
    			$con = mysql_connect(SERVERNAME,USERNAME,PASSWORD);
    			if($con)
    			{
    				mysql_select_db(DBNAME,$con);
    				$query = "select questiontext,optiona,optionb,optionc,optiond from testquestion where questionid=$qid";
    				echo $query;
    				$result = mysql_query($query,$con) or die(mysql_error($con));
    				if( $result && mysql_num_rows($result) > 0 )
    				{
    					while($row = mysql_fetch_array($result))
    					{
    						list($questiontext,$optiona,$optionb,$optionc,$optiond) = $row;
    						
    						echo '<tr><th>' . $questiontext . '</th></tr>';
    						
    						echo '<tr><td><input type="radio" id="radio" name="an" value="a"/>'.$optiona.'</td></tr>';
    						echo '<tr><td><input type="radio" id="radio" name="an" value="b"/>'.$optionb.'</td></tr>';
    						echo '<tr><td><input type="radio" id="radio" name="an" value="c"/>'.$optionc.'</td><tr>';
    						echo '<tr><td><input type="radio" id="radio" name="an" value="d"/>'.$optiond.'</td></tr>';																
    						echo '</tr>';
    					}
    				}
    				else
    				{
    					echo '<tr><td colspan="5" align="center">There is No Data</td></tr>';
    				}
    				
    			}?>
                </table>
                </div>
                <?php
    				echo '<span id="qno" style="display:none">0</span>';
    				echo '<span id="total" style="display:none">' . $total . '</span>';
    				echo '<center><input type="button" onclick="back()"  value="BACK">	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';											
    				echo '<input type="button" onclick="next()" value="NEXT"></center>';
    			?>
    </form>
    </body>
    </html>
    Last edited by Rabbit; Jul 1 '14, 05:18 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    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.

    Comment

    Working...