SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast mtran's Avatar
    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;
    Also, why people use "e" or something like that. What is it, and what is it for compared to just check_val in the following example?
    Thanks!
    Code:
    function check_val(e) {
    
      if (e.name.value==''){
        alert("Please enter your name.")
        e.name.focus()
        return false;}
          
      return true;}

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,192
    Mentioned
    191 Post(s)
    Tagged
    2 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;
    (lighten or darken to what suits you)
    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).

  3. #3
    SitePoint Wizard stereofrog's Avatar
    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':'');

  4. #4
    SitePoint Enthusiast mtran's Avatar
    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==''){.....
    is a short way of scripting. The long way should be sth like below, right?
    Code:
    function check_val() {
      if (document.formName.fieldName.value.==''){
        alert("Please enter your name.")
        document.formName.fieldName.focus()
    ....
    but why I didn't see any thing like: var e =.... in the first code. Why it still works without all of those document.forms.formName...

    Thanks a lot for your help and... patience. I need to get this confusion out of the way. It's been bugging me

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,192
    Mentioned
    191 Post(s)
    Tagged
    2 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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •