Reputation: 11
This script was placed in my forms between divs for captcha. what should I do to refresh the particular div to recall the function with refresh button (not refresh the whole form).
<script type="text/javascript">
var a = Math.ceil(Math.random() * 10);
var b = Math.ceil(Math.random() * 100);
var c = a + b
function mathCap()
{
document.write("What is "+ a + " + " + b +"? ");
/* document.write("<input id='numsCap' type='text' maxlength='4' size='4'/>"); */
}
</script>
Upvotes: 1
Views: 1922
Reputation: 3633
On the head of the document create a function that has the functionality that you need and put it on the "onclick" event of your refresh button.
<head>
function mathCap()
{
var a = Math.ceil(Math.random() * 10);
var b = Math.ceil(Math.random() * 100);
var c = a + b
var q = "What is "+ a + " + " + b +"? "
// Code to set The InnerHTML property of the div.
document.getElementById('id of the div').InnerHTML = q;
}
</head>
Upvotes: 1