Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/267210-weird-problem/
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/267210-weird-problem/#findComment-1370076
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/267210-weird-problem/#findComment-1370251
Share on other sites

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. :)

Link to comment
https://forums.phpfreaks.com/topic/267210-weird-problem/#findComment-1370256
Share on other sites

  • 3 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.