SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict fabrizio's Avatar
    Join Date
    Oct 2002
    Location
    California
    Posts
    365
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IE equivalent for 'this.value' ??

    Hello here,
    I am working to a very simple Javascript to detect what the user is selecting in a pop-up menu, but I am having trouble to make it compatible with Internet Explorer for Windows. The script works great with Firefox and any DOM compatible browser, here it is:

    http://www.looksheetmusic.com/IEissue.html

    it simply displays the value the user selects.

    I am concerned about the following line which actually I don't know how to make "IE correct":
    Code:
    var key = window.event.value;
    Probably I am asking something very stupid, but I really don't know what to do.

    Any advice and suggestion is very welcome!


    Sincerely,
    Fabrizio
    Virtual Sheet Music®, Inc.
    http://www.virtualsheetmusic.com
    Musicians Page
    http://www.musicianspage.com

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not just
    Code:
    <select onchange="handleOnChange(this);"></select>
    
    function handleOnChange(oSelect) {
        alert(oSelect.value);
    }
    But if you want your script to work (which is a bit of an overkill if you ask me), then
    Code:
    function myScriptInit() {
    	var element6 = document.getElementById('orderby');
    	addEvent(element6, 'change', function(){ modifyorderby(element6); } , false);
    
    }
     
    function modifyorderby(oSelect) {
    	alert(oSelect.value);
    }
    If you are only going to attach one onchange event, then you might consider this approach
    Code:
    function myScriptInit() {
    	var element6 = document.getElementById('orderby');
    	element6.onchange = function() {
    		modifyorderby(this);
    	}
    }
     
    function modifyorderby(oSelect) {
    	alert(oSelect.value);
    }

  3. #3
    SitePoint Addict fabrizio's Avatar
    Join Date
    Oct 2002
    Location
    California
    Posts
    365
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your reply, I found a different working way:

    http://www.looksheetmusic.com/IEissue1.html

    here is the complete code:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    <HTML><HEAD>
    <TITLE>IE issue</TITLE>
    <META http-equiv="Content-type" content="text/html; charset=iso-8859-1">
    <SCRIPT language="JavaScript" type="text/javascript">
    <!--
    
    
    
    function myScriptInit(e) {
    	if (!document.getElementById || !document.getElementsByTagName || !document.createElement) {
    		return;
    	}
    	//Default code (install listeners)
    
    	
    	var element6 = document.getElementById('orderby');
    	element6.onchange = modifyorderby;
    
    }
    
     
    function modifyorderby(e) {
    	if (!e) e = event;
    	
    	
    	var key = this[this.selectedIndex].value;
    	
    	
    	window.alert(key);
    
    		
    
    }
    
    
    
    
    
    //AUTO LOAD COMPATIBLE....
    function addEvent(elm, evType, fn, useCapture) {
     	 	// cross-browser event handling for IE5+, NS6 and Mozilla 
     	// By Scott Andrew 
      	if (elm.addEventListener) { 
        	elm.addEventListener(evType, fn, useCapture); 
        	return true; 
      	} else if (elm.attachEvent) { 
        	var r = elm.attachEvent('on' + evType, fn); 
        	return r; 
      	} else {
        	elm['on' + evType] = fn;
      	}
    }
    addEvent(window, 'load', myScriptInit, false);
    // -->
    </SCRIPT>
    
    </HEAD>
    <BODY bgcolor="#FFFFFF">
    <FORM action="" method="GET" enctype="application/x-www-form-urlencoded">
    <TABLE border="0" cellspacing="0" cellpadding="0">
    <TR><TD valign="middle">Sort By:</TD>
    <TD>
    <SELECT name="orderby" id="orderby" size="1">
    <OPTION selected value="1">Relevance & Source
    <OPTION value="2">Price
    <OPTION value="3">Title
    <OPTION value="4">
    Availability and Price
    <OPTION value="5">
    Availability and Title
    </SELECT>
    </TD></TR></TABLE>
    
    
    </FORM>
    
    
    </BODY>
    </HTML>


    Merry Christmas!

    Best,
    Fabrizio
    Virtual Sheet Music®, Inc.
    http://www.virtualsheetmusic.com
    Musicians Page
    http://www.musicianspage.com


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
  •