SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Nov 3, 2006, 00:31 #1
- Join Date
- Apr 2006
- Location
- San Jose, US
- Posts
- 27
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
form validation - simple quesiton
Hi,
I'm new to js, and learn from some tutorial about form validation, and wondering:
Why IE doesn't gray out the disabled field while FF grays it out, as in below. How to make it work in IE?
Code:document.formName.fieldName.disabled = true;
Thanks!
Code:function check_val(e) { if (e.name.value==''){ alert("Please enter your name.") e.name.focus() return false;} return true;}
-
Nov 3, 2006, 02:12 #2
- Join Date
- Jul 2005
- Location
- West Springfield, Massachusetts
- Posts
- 17,290
- Mentioned
- 198 Post(s)
- Tagged
- 3 Thread(s)
grey out disabled - "e"
Hi mtran, welcome to the forums,
I can't say why IE does or doesn't do things. But you could possible style the input using js to change the CSS style. Maybe something like
HTML Code:document.formName.fieldName.disabled = true; document.formName.fieldName.style.backgroundColor = #DDDDDD;
The "e" is the variable that accepts the argument passed to the function. It can be anything that makes sense to you. Some scripters like "short and sweet" and some like more descriptive names. Another common one you'll see in examples is "evt" (for event).Big Change Coming Soon - if you want your PMs save them now!
What you need to do to prepare for our migration to Discourse
A New SitePoint Forum Experience: Our Move to Discourse
-
Nov 3, 2006, 03:10 #3
- Join Date
- Apr 2004
- Location
- germany
- Posts
- 4,324
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
For graying out disabled fields in IE you can also use css expressions. Add the following to your style sheet
Code:input { background-color:expression(disabled?'#d4d0c8':'');
-
Nov 3, 2006, 11:14 #4
- Join Date
- Apr 2006
- Location
- San Jose, US
- Posts
- 27
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks a lot for your reply.
stereofrog, I like the way that CSS expression works.
More newbie question:
So:
Code:function check_val(e) { if (e.name.value==''){.....
Code:function check_val() { if (document.formName.fieldName.value.==''){ alert("Please enter your name.") document.formName.fieldName.focus() ....
Thanks a lot for your help and... patience. I need to get this confusion out of the way. It's been bugging me
-
Nov 3, 2006, 12:07 #5
- Join Date
- Jul 2005
- Location
- West Springfield, Massachusetts
- Posts
- 17,290
- Mentioned
- 198 Post(s)
- Tagged
- 3 Thread(s)
script differences
@stereofrog, Sometimes it amazes me how much IE-only stuff I don't know. Thanks
The "e" is the function's argument/parameter. If you look on the page with the "e" code you should see something like
<input .... onclick="check_val("this") ...
<input .... onclick="check_val("this") ...
....
The this refers to the element's "document.identification" DOM-wise.
Writing code this way can make for simpler function writing because you don't need redundant code for each process if it's going to be run many times.
The other way without the argument is good for simpler functions that do something specific.Big Change Coming Soon - if you want your PMs save them now!
What you need to do to prepare for our migration to Discourse
A New SitePoint Forum Experience: Our Move to Discourse
Bookmarks