none
How can this be done in Javascript?

    Question

  • I want to do the following with JavaScript but I don't know how. I've given my best shot at trying to explain what I want to do. Can anyone input on how it can be done?

    <SCRIPT type="text/javascript">
    function selector('glancej') {
    document.getElementById('glance') {style.display='block'};
    document.getElementById('front') {style.display='none'};
    }
    function selector('frontj') {
    document.getElementById('glance') {style.display='none'};
    document.getElementById('front') {style.display='block'};
    }
    </SCRIPT>

    <SPAN onclick="selector('glancej');">GLANCE</SPAN>
    <SPAN onclick="selector('frontj');">FRONT</SPAN>

    <IMG alt="" id="glance" src="glance.png">
    <IMG alt="" id="front" src="front.png">

    • Moved by Bill_Stewart Monday, October 03, 2011 6:18 PM Move to more appropriate forum (From:The Official Scripting Guys Forum!)
    Monday, October 03, 2011 2:52 AM

Answers

  • Let me help.  JavaScript is a Microsft scripting technology for web pages. It is also now delivered as a standard for Web development called ECMAScript.

    See:  http://en.wikipedia.org/wiki/JavaScript

    Where many become confused is that for admin scripting microsoft supports a dialect of JavaScript in WSH referred to as 'jscript'. See: http://msdn.microsoft.com/en-us/library/hbxc2t98(v=VS.85).aspx

    Microsoft now calls or refers to jscript as ECMAScript3 (JavaScript).

    This forum is primarily for admin scripting and not really set up to handle classic web scripting.  There are forums shich can and will have many web developers that can answer JavaScript questions.

    The original question is about HTML scripting (DHTML). It is not about admin scripting but appears to be about how to handle some elements on a web page.

    Here are some basic suggestions:

    Go back to the book and learn how a function is designed Ou are dong it incorrectly

    function selector('glancej') {

    • A function template does not take a string. 
    • You cannot have two functions with the same name.
    • W3C now requires all tags to be in lowercase.
    • Coding is inconsistent to due lack of understanding about how JavaScript is formed.

    He is a fix although it is not really possible to know what you are trying to accomplish.

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <script language="javascript">
    
         function selector(ele) {
              alert(ele.innerText);
              if(ele.innerText == 'GLANCE'){
                   document.getElementById('glance').style.display='block';
                   document.getElementById('front').style.display='none';
              }else{
                   document.getElementById('glance').style.display='none';
                   document.getElementById('front').style.display='block';
              }
         }
         
    </script>
    </head>
    <body>
    
    <span value="test" type="button" onclick='selector(this);'>GLANCE</span>
    <span onclick="selector(this);">FRONT</span>
    <img id="glance" src="glance.png"/>
    <img id="front"  src="front.png"/>
    
    </body>
    </html>
    
    

    A moderator might want to move this topic to a web developer forum.

     

     

     

     


    jv
    Monday, October 03, 2011 11:12 AM
  • Hi Kolusion,

    Base on my understanding, you'd like to click span Glance/Front to show/hide their corresponding images.

    I modified the code little bit .please go through it.

    <html>
    <head>
        <script type="text/javascript">
            function selector(obj) {
     
                document.getElementById('glance').style.display = 'none';
                document.getElementById('front').style.display = 'none';
     
                document.getElementById(obj).style.display = '';
            }
        </script>
    </head>
    <body>
        <span onclick="selector('glance');">GLANCE</span><span onclick="selector('front');">FRONT
        </span>
        <img alt="" id="glance" src="glance.png">
        <img alt="" id="front" src="front.png">
    </body>
    </html>

    Please let me know how it goes in your side, thanks.

    best regards,

    Yanping Wang


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com
    Microsoft One Code Framework
    Friday, October 07, 2011 5:43 AM

All replies

  • I'm afraid you're in the wrong forum for Javascript.  We just don't do any Java here, only VBS, Powershell, and CMD.
    [string](0..9|%{[char][int](32+("39826578840055658268").substring(($_*2),2))})-replace "\s{1}\b"
    Monday, October 03, 2011 3:41 AM
    • Edited by Kolusion Monday, October 03, 2011 4:20 AM
    Monday, October 03, 2011 4:17 AM
  • "Being a Microsoft site, this forum only caters for Microsoft scripting technologies."

    Well thats pretty arrogant. I definatly wouldn't to be associated with a company like that.

    Bye.

    Monday, October 03, 2011 4:22 AM
  • Let me help.  JavaScript is a Microsft scripting technology for web pages. It is also now delivered as a standard for Web development called ECMAScript.

    See:  http://en.wikipedia.org/wiki/JavaScript

    Where many become confused is that for admin scripting microsoft supports a dialect of JavaScript in WSH referred to as 'jscript'. See: http://msdn.microsoft.com/en-us/library/hbxc2t98(v=VS.85).aspx

    Microsoft now calls or refers to jscript as ECMAScript3 (JavaScript).

    This forum is primarily for admin scripting and not really set up to handle classic web scripting.  There are forums shich can and will have many web developers that can answer JavaScript questions.

    The original question is about HTML scripting (DHTML). It is not about admin scripting but appears to be about how to handle some elements on a web page.

    Here are some basic suggestions:

    Go back to the book and learn how a function is designed Ou are dong it incorrectly

    function selector('glancej') {

    • A function template does not take a string. 
    • You cannot have two functions with the same name.
    • W3C now requires all tags to be in lowercase.
    • Coding is inconsistent to due lack of understanding about how JavaScript is formed.

    He is a fix although it is not really possible to know what you are trying to accomplish.

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <script language="javascript">
    
         function selector(ele) {
              alert(ele.innerText);
              if(ele.innerText == 'GLANCE'){
                   document.getElementById('glance').style.display='block';
                   document.getElementById('front').style.display='none';
              }else{
                   document.getElementById('glance').style.display='none';
                   document.getElementById('front').style.display='block';
              }
         }
         
    </script>
    </head>
    <body>
    
    <span value="test" type="button" onclick='selector(this);'>GLANCE</span>
    <span onclick="selector(this);">FRONT</span>
    <img id="glance" src="glance.png"/>
    <img id="front"  src="front.png"/>
    
    </body>
    </html>
    
    

    A moderator might want to move this topic to a web developer forum.

     

     

     

     


    jv
    Monday, October 03, 2011 11:12 AM
  • Hi Bigteddy,

    JavaScript's name is misleading. It has no relation to Java. JScript is Microsoft's implementation. It was originally called ECMAScript but got rebranded as JavaScript for marketing reasons. So the OP's question is really about web-based client-side scripting (dynamic HTML or DHTML), best asked in a web development forum.

    Bill

    Monday, October 03, 2011 2:02 PM
  • Microsoft now calls or refers to jscript as ECMAScript3 (JavaScript).

    See: http://msdn.microsoft.com/en-us/library/hbxc2t98(v=VS.85).aspx

     

     

     


    jv
    Monday, October 03, 2011 3:55 PM
  • Hi,

    Quoting that reference:

    JScript is the Microsoft implementation of the ECMA 262 language specification (ECMAScript Edition 3). With only a few minor exceptions (to maintain backwards compatibility), JScript is a full implementation of the ECMA standard.

    I don't think it's saying Microsoft is now officially calling it ECMAScript. I think it's saying that JScript is an ECMAScript implementation. But in any case, the point is that JScript/JavaScript is not the same as Java, and the OP is really asking a DHTML question, best asked and answered in a web development forum.

    Bill

    Monday, October 03, 2011 4:14 PM
  • Thanks for clearing that up for me.  I didn't mean to be rude, I was just saying we don't do Javascript here.  Sorry I made him go away.
    [string](0..9|%{[char][int](32+("39826578840055658268").substring(($_*2),2))})-replace "\s{1}\b"
    Monday, October 03, 2011 4:17 PM
  • Hi Bigteddy,

    We do JavaScript here (at least, I do) as I much prefer JScript to VBScript for WSH scripts.

    For general DHTML questions, users might get an answer here from someone who does a lot of web development or HTAs, but they've got a better shot at a faster (and potentially better quality) answer if they ask in a web development forum.

    Bill

    Monday, October 03, 2011 4:20 PM
  • Thanks for clearing that up for me.  I didn't mean to be rude, I was just saying we don't do Javascript here.  Sorry I made him go away.
    [string](0..9|%{[char][int](32+("39826578840055658268").substring(($_*2),2))})-replace "\s{1}\b"


    Microsoft has used Jscript for years as an administrative scripting language.

    The real issue here is that the question is really a web development question.

     


    jv
    Monday, October 03, 2011 4:32 PM
  • Ok, guys, so I was wrong, so very, very wrong.  Not only is ecmascript / jscript/ javascript a 'Microsoft' technology, but we use it in administrative scripting with WSH.  And we support it on this forum.

    Now, answer me this:  Why have I never seen one single jscript post (call it what you like) in this forum?  Not one, ever?  I've seen VB Script, Cmd, Powershell, a bit of html/css, VBA even.  No Java.  Ever.

    By the same token, there are many SQL scripts that are administrative, and these I never see here either, although they are often uploaded to the Repository.  (Olaf Helper upload stacks of these SQL admin scripts).  Do we do those here too?


    [string](0..9|%{[char][int](32+("39826578840055658268").substring(($_*2),2))})-replace "\s{1}\b"
    • Edited by Bigteddy Monday, October 03, 2011 5:15 PM
    Monday, October 03, 2011 5:15 PM
  • Now, answer me this:  Why have I never seen one single jscript post (call it what you like) in this forum?  Not one, ever?  I've seen VB Script, Cmd, Powershell, a bit of html/css, VBA even.  No Java.  Ever.

    There are occasional JScript questions in this forum (type in JScript in the search box). (I presume by "Java" you really mean JavaScript/JScript.)

    By the same token, there are many SQL scripts that are administrative, and these I never see here either, although they are often uploaded to the Repository.  (Olaf Helper upload stacks of these SQL admin scripts).  Do we do those here too?

    There are some SQL admins that post here, but in general SQL stuff should go to the SQL forum (more experts there and probably faster and better quality answers).

    HTH,

    Bill

    Monday, October 03, 2011 5:36 PM
  • Ok, Bill, I concede that there are some (very few) jscript questions here.  But why so few?  Is no-one using this language with WSH? 
    [string](0..9|%{[char][int](32+("39826578840055658268").substring(($_*2),2))})-replace "\s{1}\b"
    Monday, October 03, 2011 5:43 PM
  • Hi,

    I'm not sure, but perhaps because most intros to WSH scripting have been written using VBScript. JScript is a far better language, IMO.

    Bill

    Monday, October 03, 2011 5:56 PM
  • SQL is not an administrative scripting language but can be used to administer SQL Server and other databases. This is not the same as System administration.

    Many System admins who have some responsibility for backing up databases may use vbscript or PowerShell and even use some SQL but the main push is adminitration, in the broad sense, with a script, and not administration as a DBA with SQL.

     

     


    jv
    Monday, October 03, 2011 11:06 PM
  • Hi,

    I'm not sure, but perhaps because most intros to WSH scripting have been written using VBScript. JScript is a far better language, IMO.

    Bill


    Microsoft provides equal vbscript/jscript examples in most documentation. Many of the larger Microsoft utility scripts are written in jscript.

    You do not see many posts becuse users of jscript are usualy senior or advanced admins who do not much need assistance with their scripting.

    I used jscript almost exclusively until I found that few beginners could understand it.  I switched to vbscript because that is what everyone wants.

     

     


    jv
    Monday, October 03, 2011 11:10 PM
  • Hi Kolusion,

    Base on my understanding, you'd like to click span Glance/Front to show/hide their corresponding images.

    I modified the code little bit .please go through it.

    <html>
    <head>
        <script type="text/javascript">
            function selector(obj) {
     
                document.getElementById('glance').style.display = 'none';
                document.getElementById('front').style.display = 'none';
     
                document.getElementById(obj).style.display = '';
            }
        </script>
    </head>
    <body>
        <span onclick="selector('glance');">GLANCE</span><span onclick="selector('front');">FRONT
        </span>
        <img alt="" id="glance" src="glance.png">
        <img alt="" id="front" src="front.png">
    </body>
    </html>

    Please let me know how it goes in your side, thanks.

    best regards,

    Yanping Wang


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com
    Microsoft One Code Framework
    Friday, October 07, 2011 5:43 AM
  • Yanping - I already posted that solution a few days ago. The OP has lost interest.

    Using onclick='selector(this);' help to generalize the method because we can now get access to ALL properties of teh eventing object.  In the function we just caatch:

    function selector(ele){
         alert( ele.id ):
         ....

     


    jv
    Friday, October 07, 2011 8:51 AM