moliad
moliad

Reputation: 1503

Can we run JavaScript with rendering disabled?

Context

I am working on a pretty complex web site framework which includes a lot of client side manipulation of forms with dynamic look and feel being available for switching on the fly (a lot of code runs on page load and unload).

I need to be able to change the disabled state of many inputs (or read-only, when available) of various types on the fly.

The problem

The core design of many HTML form input types are screwed up (very inconsistent at the very least) and when coupled with a server running asp.net, it gets even weirder.

More specifically, as some of you know, doing disabled="true" on any input will kill the postback since its effectively not posted when form is submitted.

A possible solution

On page unload I can pretty easily remove the disabled state of every control which uses it, ... this solves the "data integrity" issue...

But there is a BIG caveat:

The whole display flashes while the unload terminates (since all controls instantly go back to enabled), and then the page is left in a less than nominal state while the server replies.

The Killer question

is there a way for onbeforeunload or unload events to run in a way that whatever manipulations they do to the DOM isn't refreshed on screen?

OR is there a way for the visuals to show a control AS if it where disabled, but its still actually posted to the server?

OR does anyone have ideas which might nudge me towards a solution?

[Edit]
I have the chance of needing to support only Chrome, so this may open up avenues of solution for some of you Chrome geniuses.

Upvotes: 0

Views: 167

Answers (2)

user529649
user529649

Reputation:

Don't remove the disable at unload, do it upon submitting the form, and also it's disabled only not disabled="true".

Upvotes: 1

jfriend00
jfriend00

Reputation: 707696

At form post time, you could also have a second hidden form (hidden with display: none) It could either be present in the original page or created dynamically via JS. None of the items in the 2nd form are disabled. Upon submit, you then copy the values from the original form to the 2nd form and you submit the second form. You never modify anything that is visible so nothing changes on screen. You are free to use disable all you want in the presentation, but still get all values sent to the server upon submit from the 2nd copy of the form.

Upvotes: 3

Related Questions