53329 Posted April 7, 2008 Share Posted April 7, 2008 I have an onclick function that works when I only have it pulling values from a few elements but when the number starts to increase I get errors that say none of my html inputs have any properties. The onclick I'm using is about 2500 characters long. Is there a limit to the length of the code? Paraphrased the code is onclick="myfunction((document.getElementById('home').checked==true ? 1 : 0) + (document.getElementById('help').checked==true ? 1 : 0))" Just repeat the inside about 20-30 times instead of twice to get an idea of the length. So I'm not sure if the problem is the length of the code in the onclick as for all I know it is a problem with a maximum length for a function argument. I might be able to get around this a few ways but first I need to know why I'm getting the error. Firefox error console says: document.getElementById("home") has no properties But again its only when I happen to have a lot of getElementById's. If its just the one or a few it seems to work fine. Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 7, 2008 Share Posted April 7, 2008 I'm not sure of a max length, but why would you want to put that much "functionality" in the trigger? In my opinioin, a trigger is just that - just a trigger to call a function. I would suggest just using the element IDs in the trigger and have the first part of the function do the determination as to whether the elements are checked or not. Here is some sample code (not tested, but logic should be sound) onclick="myfunction('home'+'/'+'help')" Add as many IDs as needed separated by a delimeter character (in this case the forward slash) function myfunction(params) { var paramAray = params.split('/'); var inputVal for (var i=0; i<paramAray.length; i++) { inputVal += (document.getElementById(paramAray[i]).checked==true)?1:0; } //Continue with function as before and use inputVal } Quote Link to comment Share on other sites More sharing options...
53329 Posted April 7, 2008 Author Share Posted April 7, 2008 That was one of my ideas actually. Problem is that its taking information and submitting it to the server with ajax. I guess I could look for a more viable way to submit forms with ajax. And I think I already got one. So obvious I don't know how I missed it. Quote Link to comment 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.