Hi,

I click 'start' button, then start button is disabled as expected.

Once I click start button, i want to see the values of f1 and f2 on first row , values of f3 and f1 on the second row. First row is working just fine. but the second row i get only the value of f3 not the f1. Please advise!!

Thanks.

--

<html>

<?php
$_SESSION['num1'] = mt_rand(2,5);
$q1 = $_SESSION['num1'] ;

$_SESSION['num2'] = mt_rand(6,9);
$q2 = $_SESSION['num2'] ;

$_SESSION['num3'] = mt_rand(11,19);
$q3 = $_SESSION['num3'] ;
?>


<SCRIPT language="JavaScript">
<!--hide
function newtext()
{
document.getElementById("stBtn").disabled = true;
q1 = '<?php echo $q1 ;?>';
q2 = '<?php echo $q2 ;?>';
q3 = '<?php echo $q3 ;?>';



document.getElementById("f1").innerHTML = q1;
document.getElementById("f2").innerHTML = q2;
document.getElementById("f3").innerHTML = q3;
setTimeout("moretext()",9000);
 }

function moretext()
{

document.myform.one.disabled = true;
}
//-->
</SCRIPT>

</HEAD>

<BODY>

<FORM name="myform" method="post" action="sessionS1.php">

<table width='600' cellpadding='5' cellspacing='5' border='1'> 

<tr><td colspan=6 align='right'><INPUT TYPE="button" id="stBtn"  name="mytext" value="start " onClick="newtext()"></td></tr> 

<tr> <td> Q1 </td> <td><p id="f1"></p> * <p id="f2"></p>   </td> <td> <input type = 'text' size = '2' name = one > </td> </tr>
<tr> <td> Q1 </td> <td><p id="f3"></p> * <p id="f2"></p>   </td> <td> <input type = 'text' size = '2' name = two > </td> </tr>

<tr><td colspan=6 align='right'><input type='submit' value='Score' name='btn_score'></td></tr> 

</table> 

</FORM>

</body>
</html>

Because you have an element that has the same id which is f2.. javascript only read one id...
try to change second f2 to f4
then in you javascript include f4 on the innerHTML stuff

and another thing i ovserved that you have lots of post could you mark some of them solved if it's already solve.. =)

If you have repeated Id, and you don't want to change the Id name
You can use the following code ...

var myPTags = document.getElementsByTagName("p");
for(var i = 0; i < myPTags.length; i++){
    if(myPTags[i].id == "f2")  {
        myPTags[i].innerHTML = q2;
    }
}

document.getElementById("f1").innerHTML = q1;
//document.getElementById("f2").innerHTML = q2;
document.getElementById("f3").innerHTML = q3;
setTimeout("moretext()",9000);

Insted of

document.getElementById("f1").innerHTML = q1;
document.getElementById("f2").innerHTML = q2;
document.getElementById("f3").innerHTML = q3;
setTimeout("moretext()",9000);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.