Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

In what order do html INPUT properites get written?

Status
Not open for further replies.

jsteph

Technical User
Oct 24, 2002
2,562
US
Hi,
To explain the question, I have asp script which goes something like
(this is pseudo-html, just for ease of explanation):
Code:
response.write "< input type=text onfocus=""foo('y');"" onblur=""bar('x');"" value=""hello"">"
YET...when I print the innerHTML of the element in which the above is contained, I get:
Code:
<input onblur="bar('x');" onfocus="foo('y');" value=hello>
1. The "Type=Text" is missing, (how does the browser know what type of input it is?)
2. The onfocus and onblur functions are not in the order in which I wrote the html.
3. Quotes missing from Value (I'm guessing if I had a space inthe value it might retain the quotes)

Now, in the real world, my example has many more properites, and the crux of this whole issue is that I'm dynamically re-writing the html using Regular Expressions to replace certain things, such as the 'x' and 'y' hardcoded value, and many, many more things.

I wanted to do a single string.replace(regexp) in javascript to change an entire set of (up to hundreds on the page) of these elements.

My proof-of-concept on a simple table with a few rows and a few columns with simple TD's and INPUT's worked beautifully, but as I added functions and properties to the TD's and INPUT's, it fell apart due to this ordering issue, it appears I have no guarantee of which order they'll end up in!

I really, really don't want to have to write a discreet regexp for each function, sub-element, property, etc, in the element being .replaced--there are quite a few and the order really is critical if I'm to do it with a single regexp--in part because the regexp itself is created dynamically be asp, and also because each call to .replace() will add more expense--a single call is what I want.

As I said, the concept is working and will allow me to do what might otherwise take an expensive page-refresh, in a matter of milliseconds.

Is there a way to either:
A. Force the exact html as I write it
or
B. Know in advance the rules each browser (ie 6 in this case) is going to use to write the innerHTML based on my authored HTML?
Thanks very much for info on this,
--Jim
 

I would say:

A: No
B: Possibly

A: Because the browser will interpret and store it as it pleases. It probably parses the HTML and tokenises it, and un-tokenises it when you resuest innerHTML, giving to you in some predetermined order (of course, you can test this by swapping the order of your attributes around and seeing if the result is still the same).

B: See if you can find anything on MSDN, but I suspect how the internals of IE work will be a closely guarded secret. At least with open source browsers you might have a chance of seeing how it works.

Hope this helps,
Dan


The answers you get are only as good as the information you give!

 
Dan,
Thanks, that will at least save me from trying all sorts of kludges to get them to line up in a row. I've redone the regular expressions and it's not too bad a hit on performance, so it'll have to work.
--Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top