/    Sign up×
Community /Pin to ProfileBookmark

inner html limit

Hi All,

I have one select box on html page. Code is pasted below.
list has 230 objects in it. if objects are 224 then page get displayd successfully but if objects exceeds then 224 it does not get displayed. please help.

var r = new Array();
r = document.getElementById(subdivtag).rows;
var q = r.length;
var x=document.getElementById(subdivtag).insertRow(q);
var spreqtype=x.insertCell(1);
spreqtype.className=”black_ar_s”;
sname=””;
var identifier = “value(ParticipantMedicalIdentifier:” + (q+1) +”_id)”;
sname = sname + “<input type=’hidden’ name='” + identifier + “‘ value=” id='” + identifier + “‘>”;
var name = “value(ParticipantMedicalIdentifier:” + (q+1) + “_
Site_id)”;
sname = sname +”<select name='” + name + “‘ size=’1′ class=’formFieldSized12’ id='” + name + “‘ onmouseover=showTip(this.id) onmouseout=hideTip(this.id)>”;
<%if(siteList!=null)
{
Iterator iterator = siteList.iterator();
while(iterator.hasNext())
{
NameValueBean bean = (NameValueBean)iterator.next();%>
sname = sname + “<option value='<%=bean.getValue()%>’><%=bean.getName()%></option>”;
<%}
}%>
sname = sname + “</select>”;
spreqtype.innerHTML=”” + sname;

any help would be great.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@deathshadowJul 09.2014 — Given what it looks like you're doing, you REALLY shouldn't be using innerHTML for this. On the whole we're really supposed to have stopped using innerHTML a decade ago -- but really there are still many cases where its' still way too useful -- to be frank, this isn't one of them.

Build using the DOM.

Also, you're making R an array for no good reason; since JS doesn't have typing there's no reason to waste time doing that. Likewise you don't have to keep saying 'var' -- you can comma delimit new variables off one declaration. I'd also store subDivtag for a single get, since getElementById is far slower than variable access.

Though... the 'rows' attribute is an odd one if that's a DIV. What's the source for that markup being targeted look like?

I'm guessing wildly here, but really I'd be trying to do that via building the DOM up. One simple "tag making" function and it becomes really easy really quick.

var d = document; // just to make it a bit easier to work with

function makeTag(tagname, content, attribs, parent) {
var e = d.createElement(tagName);
if (content !== false) e.appendChild(
typeof content == 'object' ?
content :
d.createTextNode(content)
);
if (attribs) for (var i in attribs) e[i] = attribs[i];
if (parent) parent.appendChild(e);
return e;
}

var
d = document, // just to make it a bit easier to work with
subDivTag = d.getElementById(subdivtag),
r = subDivTag.rows,
x = subDivTag.insertRow(r.length),
spreqtype = x.insertCell(1),
prefix = 'value(ParticipantMedicalIdentifier:' + (r.length+1),
inputName = prefix + '_id)',
selectName = prefix + '_Site_id)';

makeTag('input', false, {
type : 'hidden',
name : inputName,
id : inputName
}, spreqtype);

var newSelect = makeTag('select', false, {
name : selectName,
id : selectName,
size : '1',
className : 'formFieldSized12'
// your onmouseover stuff looks like something that should be CSS' job!
}, spreqtype);

&lt;%if(siteList!=null) {
Iterator iterator = siteList.iterator();
while (iterator.hasNext()) {
NameValueBean bean = (NameValueBean)iterator.next();
%&gt;
makeTag('option', '&lt;%=bean.getName()%&gt;', {
value : '&lt;%=bean.getValue()%&gt;'
}, newSelect);
&lt;%}
}%&gt;


Not sure if that would actually run as I'm not sure if that's ASP or XSLT... and I really don't deal with either a whole lot, but should at least show enough for you to figure it out. You've also got a lot of methods and objects in there I flat out don't recognize, so I'm assuming you've got a whole lot of code we're just not seeing here.

Using the DOM is faster, leaner, cleaner, and will have no such size limit issues. The make method I added to this is based on the one from my [url=http://www.elementalsjs.com]elementals.js[/url] library.

Though honestly, if you have more than 12 options in a SELECT, all you are doing is pissing off users.
×

Success!

Help @gaatha22 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...