SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict itsource's Avatar
    Join Date
    Jun 2001
    Location
    Thailand
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can I edit this code for both Netscape and IE ?

    This code work only IE. When click each list box it display each image and has link to show big image but doesn't work in Netscape because when click new list box, the image doesn't change.

    I don't know how to write code to work both Netscape and IE.
    Code:
    <SCRIPT LANGUAGE="JavaScript">
    function choose()
    {
    	if (document.all.select1.value=="1")
    	{
    		form1.mypic.src="newsletter_traditional.gif";
    		mypiclink.href="newsletter_traditional_big.gif";
    	}
    	if (document.all.select1.value=="2")
    	{
    		form1.mypic.src="newsletter_modern.gif";
    		mypiclink.href="newsletter_modern_big.gif";
    	}
    	if (document.all.select1.value=="3")
    	{
    		form1.mypic.src="newsletter_professional.gif";
    		mypiclink.href="newsletter_professional_big.gif";
    	}
    }
    </SCRIPT>
    
    <form action="go.php" method="post" name="form1">  
    <table border=1 cellpadding=2 cellspacing=0>
    <tr>
    	<td>
    		<select  size=6 name="select1" onchange="choose()" width=100>
    				<option value="1" selected>Traditional
    				<option value="2">Modern
    				<option value="3">Professional
    		</select>
    	</td>
    	<td>
    				<a href="newsletter_traditional_big.gif" border=0 name="mypiclink" target="_new">
    						<img src="newsletter_traditional.gif" name="mypic" border=0>
    				</a>
    	</td>
    </tr>
    </table>
    </form>
    I live in Thailand. My English grammar not well.

  2. #2
    SitePoint Addict itsource's Avatar
    Join Date
    Jun 2001
    Location
    Thailand
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I change document.all to document.form1

    It has old result both IE and Netscape (not work)

    and If I change mypiclink.href to form1.mypiclink.href, IE has error form1.mypiclink is null or not an object and Netscape still has old result (notwork)
    I live in Thailand. My English grammar not well.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2002
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    there are several things in your code that would break Netscape. This code should fix your problem.

    Code:
    <script language="JavaScript">
    
    function newImage(src){
    	img = new Image();img.src = src;
    	return img;
    }
    function choose(select){
    	switch(select.options[select.selectedIndex].value){
    	case "traditional":
    		var src = traditional.src;
    		url = traditional_url;
    		break;
    	case "modern":
    		var src = modern.src;
    		url = modern_url;
    		break;
    	case "professional":
    		var src = professional.src;
    		url = professional_url;
    		break;
    	}
    	document.images["mypic"].src = src;
    }
    function getPic(){
    	window.open(url,'_blank','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
    }
    
    var traditional = newImage("newsletter_traditional.gif");
    var modern = newImage("newsletter_modern.gif");
    var professional = newImage("newsletter_professional.gif");
    
    var traditional_url = "newsletter_traditional_big.gif";
    var modern_url = "newsletter_modern_big.gif";
    var professional_url = "newsletter_professional_big.gif";
    
    var url = traditional_url;
    
    </script>
    
    <form>  
    <table border="1" cellpadding="2" cellspacing="0">
    	<tr>
    		<td><select name="select1" onchange="choose(this)" size="3" width="100">
    			<option value="traditional" selected="selected">Traditional</option>
    			<option value="modern">Modern</option>
    			<option value="professional">Professional</option>
    		</select></td>
    		<td><a href="#" onclick="getPic(); return false"><img src="newsletter_traditional.gif" name="mypic" border="0"></a></td>
    	</tr>
    </table>
    </form>
    travis

  4. #4
    SitePoint Addict itsource's Avatar
    Join Date
    Jun 2001
    Location
    Thailand
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much.

    I try to fix this code many week but can't.
    Your code work both Netscape and IE.
    I live in Thailand. My English grammar not well.


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
  •