How can i access only the specific textbox on clicking an icon next to it. I know i have to use $this, but being new i am not able to make it.
help appreciated. 🙂
JS:
jQuery(document).ready(function($) {
$('#plus').click( function(event) {
if($('.abc').val() == ''){
$('.abc').val(10);
}else{
$inc = parseInt($('.abc').val()) + 10;
$('.abc').val($inc);
}
});
});
HTML:
<form class="chkform" id="chkform" name="chkform" method=post action="">
<input type="text" class="abc" id="abc" name="abc" value="">
<img src="plus.png" id="plus" name="plus" class="plus" >
<br><br>
<input type="submit" value="submit" name="submit" >
</form>
<form class="chkform" id="chkform" name="chkform" method=post action="">
<input type="text" class="abc" id="abc" name="abc" value="">
<img src="plus.png" id="plus" name="plus" class="plus" ><img src="minus.png" id="minus" name="minus" class="minus">
<br><br>
<input type="submit" value="submit" name="submit" >
</form>
Your form isn’t very well coded, you can’t have duplicate IDs, which you have a few off.
I’ve changed the function to look for
.plusand it now gets the input field that was before it and performs the actions on that instead of both:See it working here: http://jsfiddle.net/cchana/wQc8U/