0

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>

Edited by bangla

5
Contributors
5
Replies
7
Views
4 Years
Discussion Span
Last Post by rotten69
0

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?

Edited by radhakrishna.p: getting the clarity on the problem

0

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">

Edited by radhakrishna.p: giving clarity on the solution

0

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>
0

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);

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.