Reputation: 173
I need to reload a particular div without reloading the whole page.
<div class="">
<div class="contactpagecaptchas">
<img src="/captcha.php?rand=<?php echo rand();?>" class="contactpagecaptchass" id='captchaimg'/>
<p class="change"><a href="javascript: refreshCaptcha();" class="clickto">Click to change</a></p>
</div>
<div class="contactcaptcha">
<input type="text" class="form-control" name="captcha" placeholder="Captcha" style="background-color: #f4f4f4;border: none;">
</div>
</div>
Once i click on refresh captcha text box should get cleared.
Upvotes: 1
Views: 54
Reputation: 258
Try onclick method of javascript
<div id="abc" ><?php echo rand(); ?></div>
<button onclick="refcaptcha()" >
<script>
function refcaptcha(){
var x = document.getElementById("abc")
x.innerHTML = Math.floor((Math.random() * 1000000) + 1);
//if you want to clear the captcha code than assign '' to that id
//x.innerHTML = '';
}
</script>
Upvotes: 0
Reputation: 1249
$('.clickto').click(function() {
$('[name="captcha"]').val('');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="">
<div class="contactpagecaptchas">
<img src="/captcha.php?rand=<?php echo rand();?>" class="contactpagecaptchass" id='captchaimg' />
<p class="change"><a href="#" class="clickto">Click to change</a></p>
</div>
<div class="contactcaptcha">
<input type="text" class="form-control" name="captcha" placeholder="Captcha" style="background-color: #f4f4f4;border: none;">
</div>
</div>
Upvotes: 2