SitePoint Sponsor

User Tag List

Results 1 to 16 of 16

Thread: Quick help!

  1. #1
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Quick help!

    Quick help please!

    If you want some javascript to only occur if you're using IE (like 4+), how do you specify it?

    I'd like to make it more than just IE4 but I don't know every single browser which supports the javascript command. It's field disabling and worked on IE but not NS.

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what code have you got that you need to do this.

    well by referencing an object you can do this

    PHP Code:
    if      (document.all)           {}
    else if (
    document.getelementByID){}
    else    (
    document.layer)         {} 
    other than that the best way to reference an object is this

    PHP Code:

    <script type="text/javascript">

      function 
    blah(whatcol)
      {
        
    what.style.backgroundColor=col;
      }

    </script>

    <div onmouseover="blah(this, black)">blah</div> 
    as you can see there is no need to give the attribute an id, just pass 'this' in the function call and you can use that reference handle.

  3. #3
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol what are you talking about?

    I need the javascript only to occur if the user is using IE4+

    It's a client-side form field disabling/enabling which doesn't work in NS and causes a problem.

  4. #4
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well use this then

    PHP Code:

    if      (document.all)
    {

    }
    else if (
    document.getelementByID)
    {

    }
    else    (
    document.layer)
    {


    or try this

    PHP Code:

    if (navigator.appName == "Microsoft Internet Explorer")
    {
      
    //execute this chunk of code

    or

    PHP Code:

    if (parseInt(navigator.appVersion) > 3)
    {
      
    // end of Nav4+ only if 

  5. #5
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.
    Last edited by geiger; Jun 6, 2002 at 22:58.

  6. #6
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i can't remember what the codes supposed to be like for mozilla or opera

    but just do this

    PHP Code:
    alert(navigator.appName); 
    and replace the app name accordingly

    PHP Code:
    if (navigator.appName == "Microsoft Internet Explorer")
    {
      
    //execute this chunk of code

    however what i said t you in the first place about using 'this' will be better than make cross browser scripts as it works on any browser that has js enabled.

  7. #7
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.

  8. #8
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This field disabling script works in IE and Mozilla/NS6:

    http://www.w3schools.com/dhtml/tryit..._input_disable

  9. #9
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Odd... I'll talk to my scripter. Mine isn't! It gets stuck whichever way it starts out in NS/Mozilla.

  10. #10
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I want to have multiple enabled and disabled fields, how do I edit it? Also if I want to enable and disable checkboxes, etc. can I put "this"?

    function makeDisable()
    {
    var x=document.this.name <-- does this work?
    x[0].disabled=true
    }

    function makeEnable()
    {
    var x=document.this.name <-- does this work?
    x[0].disabled=false
    }

    Do those work, and how do I add more than one?

  11. #11
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone?

  12. #12
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    as i said before use 'this' as a reference handle so it will work in any browser

    PHP Code:

    function makeDisable(what

      var 
    what.name;
      
    x[0].disabled true;


    function 
    makeEnable(what

      var 
    what.name;
      
    x[0].disabled false;

    now call it by this

    makeEnable(this) or makeDisable(this)

  13. #13
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Andrew-J2000
    as i said before use 'this' as a reference handle so it will work in any browser

    PHP Code:

    function makeDisable(what

      var 
    what.name;
      
    x[0].disabled true;


    function 
    makeEnable(what

      var 
    what.name;
      
    x[0].disabled false;

    now call it by this

    makeEnable(this) or makeDisable(this)
    Sorry I know absolutely Zero javascript so you have to talk me through this

    So if I want a checkbox switched it would be
    var x = select.viewable1;
    var x = select.viewable2;
    var x = select.viewable3;

    and field
    var x = field.description1;

    ?

  14. #14
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    erm, i'm not sure what you mean. Do you have the page online somewhere or can you post it form included

  15. #15
    SitePoint Wizard geiger's Avatar
    Join Date
    Jul 2001
    Posts
    2,459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah but its in a pass protected area. Do you have a real-time chat client?

  16. #16
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yea check my signature 'Andrew-J', i'm not sure how much help i can be at the moment tho.

    sobbering up still


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
  •