tags:

views:

500

answers:

6

I am having a strange issue in Firefox 3.5.2 with F5 refresh.

Basically, when I focus on an input field and hit f5 the contents of that input field gets copied to the next form field after the F5 refresh.

But, if you inspect the HTML source code, the values are correctly loaded. I am not having this issue in IE8 or Safari 4.0.3.

The problem does not occur if I do a hard refresh or run window.location.refresh(true).

After F5 Refresh: http://i805.photobucket.com/albums/yy339/abepark/after.jpg

Here's an overview of what's going on.

+1  A: 

Browsers can remember form field contents over a refresh. This can really throw your scripting off if it is relying on the initial value of a field matching what's in the HTML. You could try to prevent it by calling form.reset() at the start.

Different browsers have different strategies for detecting when a form or a field is the same as in the previous page. If you have clashing names, or names that change on reload, it is very possible to end up confusing them. Would have to see some code to work it out for sure.

bobince
A: 

In the backend, I am using ASP.NET MVC 1.0 with the Spark View engine. When I examine the source code after an F5 refresh in Firefox 3.5.2, the page renders correctly; however, if you look at the page visually the adjacent form field field gets populated with the value from the previous field.

I included enough code so you can just get an idea of what I'm trying to do. Again, the rendering is fine and the final view/HTML code is fine. It's what I see on the screen that is incorrect. I am using hidden vars; but the issue occurred before using it as well.

Note in the code below, I have 2 distinct ID fields: "date_{projectTask.ProjectTaskId}" and "finishDate_{projectTask.ProjectTaskId}, which gets renders to something like "date_1" and "finishDate_2".

<table>
    <for each="ProjectTask projectTask in projectTasksByProjectPhase">
        <input type="hidden" value="${projectTask.ProjectTaskId}" />
        <tr>
        <td class="date">
            <div class="box">
                <div class="datefield">
                    <input type="text" id="date_${projectTask.ProjectTaskId}" value="${startDate}" /><button type="button" id="show_${projectTask.ProjectTaskId}" title="Show Calendar"><img src="~/Content/yui/assets/calbtn.gif" width="18" height="18" alt="Calendar" ></button>
                </div>
            </div>
        </td>
        <td>
            <div class="box">
                <div class="datefield">
                    <input type="text" id="finishDate_${projectTask.ProjectTaskId}" value="${finishDate}" /><button type="button" id="finishShow_${projectTask.ProjectTaskId}" title="Show Calendar"><img src="~/Content/yui/assets/calbtn.gif" width="18" height="18" alt="Calendar" ></button>
                </div>
            </div>
        </td>
    </tr>
    </for>
    </table>

FYI: ${} are used to output variables in the Spark View engine.

I am also using the YUI 2.7 Connection to make Ajax calls to update the datebase for "change" and "enter/tab key press" events. I am able to verify that the AJAX calls are made correctly and the form field values are still valid.

The problem occurs when I just do a F5 refresh; for some reason, the "finishDate_1" gets populated with the value from "date_1".

This problem occurs just by clicking on "date_1" and hitting F5; so, the adjacent field just gets populated even if there are no AJAX calls.

Here's the Javascript code I call towards the end of the body"

YAHOO.util.Event.onDOMReady(
    function() {
        var idList = YAHOO.util.Dom.getElementsBy(function (el) { return (el.type == 'hidden'); }, 'input');
        len = idList.length;

        var startDatePickers = new Array();
        var finishDatePickers = new Array();

        for (var i = 0; i < len; i++) {
            var id = idList[i].value
            startDatePickers[i] = new DatePicker("date_" + id, "show_" + id, "cal_" + id);
            startDatePickers[i].valueChanged.subscribe(updateDate, 'S');
            finishDatePickers[i] = new DatePicker("finishDate_" + id, "finishShow_" + id, "finishCal_" + id);
            finishDatePickers[i].valueChanged.subscribe(updateDate, 'F');
        }
    }
}

The form field gets copied over before any Javascript code is processed because I call the Javascript code towards the end of the body after all HTML is rendered. So, I'm guessing it's a refresh issue in Firefox? What do you guys think?

As you can see above, I created my own calender date picker objects which allows you to either enter the date in the text manually or by clicking on a button to view the calendar and select a date. Once you enter or select the date, an AJAX call will be made to update the datebase in the back end.

Thanks everybody for the quick responses.

A: 

One more comment: I'm not using a form. All the input changes are handled via the YUI Connection manager.

I am trying to create a table that has just edit-in-place table cells or input fields (like the calendar date picker above).

Thanks again!

+3  A: 

I believe the thing you should look into is the automplete attribute, you should set it to off on the input box. However be careful since this will trigger 2 effects.
1: when you refresh the page it won't remember the old values 2: the default dropdown of the already used values on that input box will also be disabled.

If you want to keep the second behavior you should set the autocomplete attribute back to on with JS.

khel
A: 

@Anonymous: whoever you are, you are awesome!

@bobince: thanks for the feedback as well.

I added a dummy form tag with the attribute autocomplete="off" and that solved the problem! I was scratching my head because I didn't get this issue in Safari 4.0.3 or Internet Explorer 8.

<form action="" autcomplete="off">
<!-- my code -->
</form>

The values were loading correctly in the back end (ASP.NET MVC 1.0/Spark View engine) and the HTML source code reflected this, but the input field values were not getting populated correctly. I was using the YUI Connection Manager and Javascript to support edit-in-place and the date pickers. I tried changing the XHR call to a GET call instead of POST and the same issue was happening.

Anyway, the problem was that the Firefox was not setting the correct values for the input fields for F5 refreshes.

Again, thanks so much! You guys rock!

AbeP
A: 

All element id's must be unique, if two elements have same id's then that could be reason why Firefox inserts same values to elments that didn't orginally have those values entered.

newbie