Ibrahim Azhar Armar
Ibrahim Azhar Armar

Reputation: 25745

how to improve speed of html form with thousand of input elements

i have a form where i need to insert an item, here is the html of the form.

<form action="test.php" class="form" method="post">
    <?php for($i=0; $i<=500; $i++): ?>
        <div class="formRow itemList">
            <select class="chzn-select" tabindex="2" name="items[]">
                <option value="3">Toys</option>
                <option value="4">Books</option>
                <option value="5">Shirts</option>
                <option value="6">iPad</option>
            </select>
            <span style="width:7%;float:left;margin-left:2%;" style="">
                <input type="text" name="quantity[]" class="est_quantity" placeholder="quantity" value="10"/>
            </span>
            <span style="width:7%;float:left;margin-left:2.5%;" style="">
                <input type="text" name="cost[]" class="est_cost" placeholder="cost" value="100"/>
            </span>
            <span style="width:7%;float:left;margin-left:2.5%;" style="">
                <input type="text" name="rate[]" class="est_rate" placeholder="rate" rate="200"/>
            </span>
            <span style="width:7%;float:left;margin-left:2.5%;" style="">
                <input type="text" name="size[]" class="est_size" placeholder="size"/>
            </span>
            <span style="width:7%;float:left;margin-left:2.5%;" style="">
                <input type="text" name="cartonnum[]" class="est_carton_no" placeholder="carton no."/>
            </span>
            <span style="width:8%;float:left;margin-left:2.5%;" style="">
                <input type="text" name="numofcarton[]" class="est_cartons" placeholder="ctns."/>
            </span>
            <span style="width:8%;float:left;margin-left:2.5%;" style="">
                <input type="text" name="qtyctn[]" class="est_qtyctn" placeholder="qty/ctn"/>
            </span>
            <span style="width:7%;float:left;margin-left:2.5%;" style="">
                <input type="text" name="cbm[]" class="est_cbm" placeholder="cbm"/>
            </span>
            <div class="clear"></div>
            <a href="#" class="itemRemove">Remove</a>
        </div>
    <?php endfor; ?>
</form>

and it goes like this.

The code is tested on:

when i tried executing the code i get serious performance, here is the stats.

Page Loading Time:

Input element response time on focus of mouse and keyboard:

here is where thing tends to get out of bounds.

The weird thing i noticed is when i remove <form> attribute from the code. the performance is improved with a very little lag or no lag on both the browser. i have no idea whatsoever is causing this behavior.

i am inserting the rows for form elements dynamically using this plugin : MultiField

so my question is:

any type of libraries that could boost the performance, tips, or anything that could help me improve the performance is greatly appreciated.

thank you.

Upvotes: 1

Views: 4115

Answers (1)

paxdiablo
paxdiablo

Reputation: 881323

Okay, so sometimes you need to enter 300-500 items. Not always. And do you really need to enter them all on one page?

I'd be pretty annoyed if I'd entered 497 items onto a web form and then my browser crashed on me. That would be followed pretty quickly by a rather abusive tech support phone call to your offices :-)

Find a way to persist smaller amounts of data (say ten items at a time) so you don't need all those input fields at once. This should both speed up your performance and make you a little safer from psychotic customers.

For example, shove them into a server side database ten items at a time, identified by a cookie value stored on the client side. The ten-items-at-a-time scenario is a nice page size (the user edits their list in ten-item chunks). Web-based commerce does this sort of stuff all the time, with their shopping carts and such.

When users want to submit the entire list, the cookie value is used to tie together all the pages to submit a cohesive unit of work.

Upvotes: 4

Related Questions