Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
I have the following div tag: (jobform)

<!--jobform-->
<div class="jobform" onclick="SetChecks();">
<div class="jobform_l" ><?php _e('Category');?> : <span class="required">*</span>      </div>

<div class="jobform_r" >

<?php require_once (TEMPLATEPATH . '/jobs_category.php');?>
</div>
<div class="aglabel">Job Poster :</div>
</div><!--jobform-->


I am generating an array of checkboxes (Categories), since I dont have the checkbox tags I will need to capture the event of onclick on this div and check/uncheck certain checkboxes. Like when one is checked I want the other one to be unchecked. So I have implemented the following javascript to do that:

JavaScript
<script type="text/javascript">
function SetChecks() {
Alert("test");
if(document.getElementById('category_41').checked)
{
document.getElementById('category_39').checked = false;
}
else if(document.getElementById('category_39').checked)
{
document.getElementById('category_41').checked = false;
}
</script>

But for some reason it is not being triggered, I event tried putting an Alert() just to make sure it is being clicked or no. And it is not.
Posted
Updated 4-Dec-11 19:14pm
v4
Comments
[no name] 4-Dec-11 23:31pm    
EDIT: added code block
Al Moje 4-Dec-11 23:32pm    
Hi,
Try to use
OnClientClick="SetChecks();"
Mastersev 4-Dec-11 23:40pm    
I'm using this in wordpress(php) it's not asp.net but I will try
Sergey Alexandrovich Kryukov 4-Dec-11 23:52pm    
OK, bad code; why those strange numeric IDs? This is not supportable. You need to create a simplified but full code, otherwise there is nothing talk about.
--SA
Mastersev 5-Dec-11 1:05am    
The IDs are not important right now, it's not even triggering. The alert() method is not being displayed when I check the checkboxes.

1 solution

Javascript is case sensitive, so even if your method would have been triggered it would cause a runtime error. Alert needs to written as alert.

Please fix that and come back with your results.

Regards,

—MRB
 
Share this answer
 
Comments
Mastersev 5-Dec-11 2:33am    
thank you
Manfred Rudolf Bihy 5-Dec-11 9:41am    
You're welcome!
Did it fix your issue or are you still experiencing the same problem as before?
Mastersev 5-Dec-11 10:56am    
Yes it did. So the alert() was not being triggered because of the typo but I also was checking the wrong IDs. Once the alert() started working I was able to trace the values and check the correct ones in my IF statements.

Thank you again for taking the time and helping me out.
Wonde Tadesse 5-Dec-11 12:15pm    
5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900