/    Sign up×
Community /Pin to ProfileBookmark

newbie – max num chars allowed in function param?

Hi All

just a quick Q:
I have a page working perfectly that passes up to 10-12k worth of data into a function via an ‘onClick’ event. That onClick is one of the <img..>’s attributes, directly. In case later that (dynamic) data gets larger, am I toying with potential problams because of some limit – either a limit in what can be passed into a JS function, or else a limit in the max num of characters allowed in an element’s attribute(s)?

What do you think is the reasonable amount that I can pass before things start to break? I may need to go up to 50k. 100k maybe, but I doubt that much.

Thanks!
-Govinda

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@PadonakAug 03.2010 — i'm not sure that this is the answer to your question but hope this info may be interesting to you. take a look at these links:

http://www.w3.org/2001/tag/doc/whenToUseGet.html#checklist

http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.1.1
Copy linkTweet thisAlerts:
@KorAug 03.2010 — JavaScript (in fact ECMAScript) has no limit lenght set to a value/string/argument. But in practice it depends on the browser and its capacity to memorize huge strings. People have different opinions about that, but I would say that a reasonable limit should be under 2^20 characters. Regarding the KB, I have worked successfully with 50KB strings with no problem, in all the browsers.
Copy linkTweet thisAlerts:
@wdgovindaauthorAug 03.2010 — OK, thanks guys for your feedback.

Padonak,

I am using that function to generate another <tr> which contains a few form inputs... which then allows the user to input another person to a collection of people (db records). The JS function parameter whose length I asked about contains a replicate of a <select> menu (and its <options>s) offering a list of existing people for the given category (orig <tr> they clicked to be able to add another person in that same category). I did not know another quick way of replicating exactly the select menu when recreating an original dyanamic table row, dynamically with JS. I thought of using an AJAX call.. but the method I used seemed more direct to me.

I hear you about GET vs. POST. Thanks!

-Govinda
Copy linkTweet thisAlerts:
@wdgovindaauthorAug 03.2010 — probably more than the size limit for JS function arguments, I was concerned about going over any limit to the length of an HTML element's attribute value (e.g. my onClick attribute where I pass the JS function argument which is that <select> menu in its entirety).
Copy linkTweet thisAlerts:
@KorAug 03.2010 — How, in fact, does you code looks like? What in fact are you doing? can you detail your aim?
Copy linkTweet thisAlerts:
@wdgovindaauthorAug 03.2010 — HI Kor

yes, let me try to summarize:

imagine several <tr>s... one for each state of the USA. User can assign one or more person ("dealer") to each state. They can use the text form inputs to hand-enter the name/phone/email of the dealer for that state.. or they can use a <select> menu to choose from a list of people that have been pre-determined to be suitable people for that given USA state. The <option>s in that select menu are dynamically populated and different for each state... and change from day to day.


When the page loads there is only one <tr> per state. But the user can click an image at the end of the <tr> to add another dealer-slot (<tr>) to the <table> which creates (via JS) another <tr> for that same state. I have to create all those form inputs found in the original <tr> for the existing dealer for that state.. so they match (but just with incrementing counters in the names) .. so another dealer can be input for the state. The <select> menu (whose contents is not known except by what rendered for the first dealer slot for that state) must be replicated and added to the DOM for the user to have the same choices of pre-determined people suitable for that state.

so to accomplish this.. I use the following:

(note i am using a server-side scripting language that uses square brackets to delineate internal variables and define built-in functions etc.)

[code=html]<span id="addDealerGif_[thisStateIndex]_[thisStateThisDealerIndex]" style="border:0px solid #eee;"><img src="images/addDealerThisState.gif" alt="" width="73" height="27" onClick="addDealerThisState([thisStateIndex],[thisStateThisDealerIndex],'[rowColor]','[stateName]','[URLescaped][stuffAvailDealersPopupOptionsThisState][/URLescaped]');" style="border:2px solid #eee;" onmouseover="this.style.border='2px solid #f9f'" onmouseout="this.style.border='2px solid #eee'" /></span>[/code]

The addDealerThisState JS function adds the new dealer's <tr> and all the form inputs necessary for the user to be able to then submit the form and effectively add another dealer to the database for the given USA state. Everything I need to pass to that function is short *except* for the <select> menu's <option>s .. which can be 20-50k in length... what I am holding in the variable named above as "[stuffAvailDealersPopupOptionsThisState]".

Do you follow?

If not, then let me re-focus my question by just asking:

given the above snippet of HTML, do you think the 'onClick' could break (or might the <span>... , or <img...> break) - if the onClick value was too long? ...on account of the value I have for "[stuffAvailDealersPopupOptionsThisState]"? If so, what length might be the breaking point?
×

Success!

Help @wdgovinda spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...