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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form validation - browser querk 1

Status
Not open for further replies.

scooby

Programmer
Dec 9, 2000
1
GB
Im using a validator property..... <INPUT TYPE=&quot;TEXT&quot; NAME=&quot;FIRSTNAME&quot; validator=&quot;required&quot; SIZE=20 > ... so I can loop through a form.elements array and identify which regular expression to validate the different input fields against. The whole thing works fine in IE5+, NS4+ just does not seen to recognise that the validator property exists. Is this true? Any other info?
 
it's not even in m$ docs, nor in ns dev doc :-/
 
validator property was probably what is called an expando property. IE4+ (i think) supports expando properties, where as NS doesn't support them at all. Expando properties are properties which can be arbitrarily (?) added to any object or element and accessed later. So whatever script you are using is expecting this property to exist, but NS doesn't see it. jared@aauser.com
 
is that like redefining an object (i mean adding an attribute to an existing object) or more like using a &quot;hidden&quot; attribute ?
it makes me think that anyway in both browser you can redefine objects
 
No, your not just redifining a property:

<script>
print = &quot;I am cool&quot; //oops redefined window.print!!
</script>

but more like:

<div id=&quot;fut&quot;></div>
<script>
fut.mynewproperty='this is an expando'
</script> jared@aauser.com
 
sorry, my question was unclear : in your example, i would have been asking if mynewproperty was actually already defined but kind of hidden (not documented not used) or if it was you who created this property (that means, adding a new attribute to an object = redefine this object)
thanx for the answers :)
 
Oh ok. mynewproperty is one that was created by me, not a hidden property of some sort. I don't think Netscape will allow you to add and access and modify properties like that, but you can also add the expando property like this:

<div id=&quot;fut&quot; mynewproperty=&quot;an expando&quot;></div>

and it will be accesible through script jared@aauser.com
 
that's gorgeous if you can add attributes to existing objects !! how about methods ?? can you define a new function for an existing object (!! then i can create a window.open_without_scrolls() or anything !!! loaaads of fun !!)
thanxthanxthanx :)
 
well, its easy to add to methods to the window object, just declaring a function is actually attaching to the prototype of window (i think), so:

<script>
open_without_scrolls()
{

}
</script>

adds method named open_without_scrolls to the window object. But, adding a method to all arrays, perhaps one that searches an array for a value and returns true if its found or false if its not could be added like so:

function Array_contains()
{
//blah blah blah
}
Array.prototype.contains=Array_contains

Now every array you ever use can use that method. This will work in IE and NS.

But, you cannot however, using any technique I know of, arbitrarilly add methods to html elements (except maybe by using ie5+ behaviors, but don't ask me about those)

jared@aauser.com
 
&quot;But, you cannot however, using any technique I know of, arbitrarilly add methods to html elements &quot;
--> just when i was starting to think &quot;hey why don't we create/redefine our own dom then ?&quot; ... ;)
just another question and i'll stop garbaging this thread, but what is the scope of an added method (in your example, if i define the function array_contains in pageA.hml, will it still be known in pageB.htm (same site same session) ? or do i have to include a file ? or what ?)
 
It has normal scope for a defined function. So if you create a pop-up window, and you don't want to include the file again, you'd have to create you're array in the opener and use it there. I've made a bunch of prototype functions for arrays and strings on a site I have, if you wanna take a look (beware I am not a nice man and only fully support IE5.5, though IE5 should have no problem viewing it) jared@aauser.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top