Reputation: 752
I want to know if an image button can be disabled? When the user has added in the number of questions they need:
if (qnum == <?php echo (int)$_SESSION['textQuestion']; ?>)
then I want to disable the image button, but how can this be done?
Below is what I attemted but it didn't work:
//HTML
<a onclick="return plusbutton();">
<img src="Images/plussign.jpg" width="30" height="30" alt="Look Up Previous Question" class="plusimage" name="plusbuttonrow"/>
</a>
...
//jquery
if (qnum == <?php echo (int)$_SESSION['textQuestion']; ?>) {
$(".plusimage").attr("disabled", "disabled");
}
Upvotes: 1
Views: 1096
Reputation: 3561
Don't use JQuery for that! Use just php (Do you have an image for the disabled button?? Images/plussignDISABLED.jpg ?? )
EDIT I just changed qnum to a php variable $numberOfQuestions. I suppose this variable will hold the numer of questions that the user has done (same as your javascript qnum I suppose...)
<?php
if ($numberOfQuestions == $_SESSION['textQuestion']) {
?>
<img src="Images/plussignDISABLED.jpg" width="30" height="30" alt="Look Up Previous Question" class="plusimage" name="plusbuttonrow"/>
<?php
}else {
?>
<a onclick="return plusbutton();">
<img src="Images/plussign.jpg" width="30" height="30" alt="Look Up Previous Question" class="plusimage" name="plusbuttonrow"/>
</a>
<?php } ?>
Upvotes: 1
Reputation: 14044
use prevent default
$("a").click(function(e) {
e.preventDefault();
});
you should properly use a id for the image, since this would disable all a elements onclick. Or maybe something along
$(".plusimage").parent().click(function(e) {
e.preventDefault();
//then you can also change the image to a disabled version inhere :)
});
EDIT: you just changed your question, and seen in that light, im curious, since you are generating the output with php at page load, how come you want to disable it with jquery? Why not just output it from the server with the image disabled?
Upvotes: 3
Reputation: 5210
You could set prevetDefault on the 'a', however, there isn't a 'disabled' attribute for images.
$('a').click(function(event){
$(this).preventDefault();
});
Upvotes: 1