njdubois Posted August 17, 2012 Share Posted August 17, 2012 This works: function total_points() { cur_point_total=3; document.getElementById("current_points").value=cur_point_total; } And this doesn't (but it does work in a vb.net webbrowser control): function total_points() { cur_point_total=3; if (document.getElementById("p4_No_Intro").checked==true) { cur_point_total--; } document.getElementById("current_points").value=cur_point_total; } What am I missing? Thanks Nick Quote Link to comment https://forums.phpfreaks.com/topic/267210-weird-problem/ Share on other sites More sharing options...
requinix Posted August 17, 2012 Share Posted August 17, 2012 What am I missing? A description of what it does. We don't know what "works" and "doesn't work" mean. Quote Link to comment https://forums.phpfreaks.com/topic/267210-weird-problem/#findComment-1370075 Share on other sites More sharing options...
njdubois Posted August 17, 2012 Author Share Posted August 17, 2012 Sorry! I'm new to javascript and I was hoping there was a blaring syntax error in the if statement that I wasn't catching. I have a form with inputs that look like this : <input type="checkbox" name="p4_No_Intro" value="True" onclick="total_points()" /> When they check or uncheck the checkbox, it should call total_points. The code shown that works sets a textbox to the point total. The code shown that doesn't work does nothing. Its as if its not even being called. Thanks for the fast reply, I hope this helps you help me! Nick Quote Link to comment https://forums.phpfreaks.com/topic/267210-weird-problem/#findComment-1370076 Share on other sites More sharing options...
Christian F. Posted August 17, 2012 Share Posted August 17, 2012 name != id, that's your problem I suspect. Quote Link to comment https://forums.phpfreaks.com/topic/267210-weird-problem/#findComment-1370109 Share on other sites More sharing options...
njdubois Posted August 17, 2012 Author Share Posted August 17, 2012 if I understood what you meant by name!=id correctly, you meant that I need to have both name and Id in the input element. like this : <input type="checkbox" name="p4_No_Intro" id="p4_No_Intro" value="True" '.$p4_No_Intro_Check.' onclick="total_points()" /> That doesn't work either? So I'm pretty sure I didn't understand you? function total_points() { cur_point_total=3; if (document.getElementById("p4_No_Intro").checked==true) { cur_point_total--; } document.getElementById("current_points").value=cur_point_total; } This chunk of code worked fine in the web browser control in my vb.net app. But when I try to load the page in a normal webbrowser, nothing happens when I check an input. The textbox "current_points" never gets set to cur point total. If I take the whole if statement out the current points textbox gets set to what ever i have cur point total set to. To me, it appears as if the if statement has some flaw or error in it that I am not seeing, but why would it work in a simple watered down webbrowser that is the control in vb.net, but not a full blown web browser??? What ever it is I'm missing has to be the simplest thing, and I'm gonna have one of those palm to forehead moments. Thanks for reading this, and thanks for the reply! Nick Quote Link to comment https://forums.phpfreaks.com/topic/267210-weird-problem/#findComment-1370251 Share on other sites More sharing options...
Jessica Posted August 17, 2012 Share Posted August 17, 2012 The easiest way to debug javascript errors is installing Firebug in Firefox and using that. It should help you. Quote Link to comment https://forums.phpfreaks.com/topic/267210-weird-problem/#findComment-1370252 Share on other sites More sharing options...
xyph Posted August 17, 2012 Share Posted August 17, 2012 The easiest way to debug javascript errors is installing Firebug in Firefox and using that. It should help you. Or Chrome with it's built-in developer tools (Ctrl+Shift+J for JS console) Quote Link to comment https://forums.phpfreaks.com/topic/267210-weird-problem/#findComment-1370254 Share on other sites More sharing options...
Jessica Posted August 17, 2012 Share Posted August 17, 2012 The easiest way to debug javascript errors is installing Firebug in Firefox and using that. It should help you. Or Chrome with it's built-in developer tools (Ctrl+Shift+J for JS console) I'm using Chrome now and I always forget about that. I'll have to try it out and see how it compares. Quote Link to comment https://forums.phpfreaks.com/topic/267210-weird-problem/#findComment-1370256 Share on other sites More sharing options...
xyph Posted August 17, 2012 Share Posted August 17, 2012 I'm using Chrome now and I always forget about that. I'll have to try it out and see how it compares. Yeah, I've pretty much dropped Firebug since they added the 'Preserve log upon navigation' option Quote Link to comment https://forums.phpfreaks.com/topic/267210-weird-problem/#findComment-1370286 Share on other sites More sharing options...
njdubois Posted August 17, 2012 Author Share Posted August 17, 2012 Didn't even know something like that was available. I will take a look at it tomorrow morning when I'm back at work. Thanks for the direction! Nick Quote Link to comment https://forums.phpfreaks.com/topic/267210-weird-problem/#findComment-1370289 Share on other sites More sharing options...
Adam Posted August 18, 2012 Share Posted August 18, 2012 You can't beat Chrome's debugging tools in my opinion. Took me a while to make the move, but I wouldn't go back now Quote Link to comment https://forums.phpfreaks.com/topic/267210-weird-problem/#findComment-1370426 Share on other sites More sharing options...
njdubois Posted September 5, 2012 Author Share Posted September 5, 2012 Hey, wanted to let you all know that the debug tools in chrome helped me to solve my problem. I didn't have an id set for one of my checkboxes and it was giving a "cant test checked for null" error. Again, many thanks! Nick Quote Link to comment https://forums.phpfreaks.com/topic/267210-weird-problem/#findComment-1375381 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.