Hi,
I am generating a random number. Then i click start. How can i see random value of q1 in html row after i click on start button?

<!DOCTYPE html>
<html>

<HEAD>


<SCRIPT language="JavaScript">
<!--hide
function newtext()
{
var q1=Math.floor(Math.random()*11)
document.myform.mytext.value=q1;
setTimeout("moretext()",4000);
 }

function moretext()
{
document.myform.mytext.disabled = true;
}
//-->
</SCRIPT>

</HEAD>

<BODY>

<FORM name="myform">
<table width='600' cellpadding='5' cellspacing='5' border='1'> 

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


 <tr>  <td> q1 *  2    </td> <td> <INPUT type="text" name="mytext"  value="" size="30"> </td> </tr> // once i click start, how can i see random value of q1 in html row?



<tr><td colspan=6 align='right'><INPUT TYPE="button" name="but1" value="Submit!" onClick="newtext()"></td></tr> 

</table> 

</FORM>

</body>
</html>

This line

<SCRIPT language="JavaScript">

Chant it to

<Script type="text/javascript">

you have done perfectly to place random number into textbox

i dont know why you are asking this question.

could you tell me the reason?

suggestion only:

instead of calling moretext() for every 4 secs in your code

try to make the textbox disabled by setting property **"disabled = true" **like as follows

 <INPUT type="text" name="mytext"  value="" size="30" disabled = "true">

Check this Ex.. I think it will help you.....

<!DOCTYPE html>
<html>

<HEAD>


<SCRIPT language="JavaScript">
<!--hide
function newtext()
{
var q1=Math.floor(Math.random()*11)
document.myform.mytext.value=q1*2;
document.getElementById('q1Value').innerHTML=q1;
setTimeout("moretext()",4000);
 }

function moretext()
{
document.myform.mytext.disabled = true;
}
//-->
</SCRIPT>

</HEAD>

<BODY>

<FORM name="myform">
<table width='600' cellpadding='5' cellspacing='5' border='1'> 

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


 <tr>  <td> <span id="q1Value">0</span> *  2  =  </td> <td> <INPUT type="text" name="mytext"  value="0" size="30"> </td> </tr> // once i click start, how can i see random value of q1 in html row?



<tr><td colspan=6 align='right'><INPUT TYPE="button" name="but1" value="Submit!" onClick="newtext()"></td></tr> 

</table> 

</FORM>

</body>
</html>

since you're only generating one thing which is a random number, then try printing out in the browser by using this command in JS.

document.writeline("your random number is: " + q1);

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.