SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2008
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onclick problems in IE

    Hello!
    This code works fine in FF but fails in IE. Nothing happens at all. When the user clicks the image, the link code should be generated in the "linkCode" input field...
    Any suggestions?

    Code HTML4Strict:
            <fieldset id="linksInfo">
                <legend>
                    Generate a link
                </legend>
                <ul>
                    <li>
                        <label for="linkAdress">Skriv in l&auml;nkadressen h&auml;r:</label>
                        <input type="text" name="linkAdress" id="linkAdress" />
                    </li>
                    <li>
                        <label for="linkText">Ange texten som ska l&auml;nkas:</label>
                        <input type="text" name="linkText" id="linkText" />
                    </li>
                    <li>
                        <label for="linkTitle">Skriv in titeltext för l&auml;nken:</label>
                        <input type="text" name="linkTitle" id="linkTitle" />
                    </li>
                    <li>
                        <img src="inc/b/adlink_button.gif" width="112" height="35" id="adLink" alt="Skapa länk" />
                    </li>
                    <li>
                        <label for="linkCode">Klistra in detta i texten:</label>
                        <input type="text" name="linkCode" id="linkCode" />
                    </li>
                </ul>
            </fieldset>

    Code JavaScript:
    var Linkmaker =
    {
    	init: function()
    	{
    		var ad = document.getElementById("adLink");
    		ad.onclick = Linkmaker.makeLink;
    	},
     
    	makeLink: function()
    	{
    		var adress = document.getElementById("linkAdress").value;
    		var title = document.getElementById("linkTitle").value;
    		var text = document.getElementById("linkText").value;
     
    		document.getElementById("linkCode").value = '';
    		document.getElementById("linkCode").value = "<a href='" + adress + "' title='" + title + "'>" + text + "</a>";
    		document.getElementById("linkAdress").value = '';
    		document.getElementById("linkTitle").value = '';
    		document.getElementById("linkText").value = '';
    	}
    };

    //Fredrik
    You know I'm not gon diss you on the internet
    Cause my mama taught me better than that

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Works for me in FF and in IE

    In my test code I made sure that core.js was included, and that the following line was included, to get things going.

    Code javascript:
    Core.start(Linkmaker);
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2008
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've made sure that core.js is included and that the last line is in place, but it still wont work in IE. Any ohter ideas? And by the way, I live in Sweden, but my brother lives in Christchurch. I was over there just two months ago. Lovely contry...
    You know I'm not gon diss you on the internet
    Cause my mama taught me better than that

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Because everything looks and test fine from what you've posted, a look at an actual test page is likely to be the next stage of troubleshooting.

    Thanks the the nice comments about New Zealand. I do envy Sweden though on having well built homes. here in NZ it doesn't get dangerously cold enough for many to do things properly.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2008
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All files are now uploaded to http://www.ovansidan.com/test.php. Still not working...
    You know I'm not gon diss you on the internet
    Cause my mama taught me better than that

  6. #6
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have a comma after the closing curly brace on line 50 of linkmaker.js - it shouldn't be there.
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  7. #7
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, can I suggest that you create a function to get element's by their ID?

    Code JavaScript:
    function getById(e) {
        return document.getElementById(e);
    }

    SO this:

    Code JavaScript:
    var Linkmaker =
    {
        init: function()
        {
            var ad = document.getElementById("adLink");
            ad.onclick = Linkmaker.makeLink;
        },
     
        makeLink: function()
        {
            var adress = document.getElementById("linkAdress").value;
            var title = document.getElementById("linkTitle").value;
            var text = document.getElementById("linkText").value;
     
            document.getElementById("linkCode").value = '';
            document.getElementById("linkCode").value = "<a href='" + adress + "' title='" + title + "'>" + text + "</a>";
            document.getElementById("linkAdress").value = '';
            document.getElementById("linkTitle").value = '';
            document.getElementById("linkText").value = '';
        }
    };

    Now becomes:

    Code JavaScript:
    var Linkmaker =
    {
        init: function()
        {
            var ad = getById("adLink");
            ad.onclick = Linkmaker.makeLink;
        },
     
        makeLink: function()
        {
            var adress = getById("linkAdress").value;
            var title = getById("linkTitle").value;
            var text = getById("linkText").value;
     
            getById("linkCode").value = ''; //btw, this line isn't necessary
            getById("linkCode").value = "<a href='" + adress + "' title='" + title + "'>" + text + "</a>";
            getById("linkAdress").value = '';
            getById("linkTitle").value = '';
            getById("linkText").value = '';
        }
    };
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  8. #8
    SitePoint Enthusiast
    Join Date
    Feb 2008
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I love you JimmiyP! I want to spend the rest of my life with you, finding and fighting commas gone bad... No but seriously, big thanks! I can't belive I didn't see it myself. I think I have a special case of dyslexia that prevents me from reading commas. I don't want anyone to think that I post here without checking for theese kinds of errors first... And thanks also for spoting the unnessesary line of code, it's there because the next line had a += before...
    You know I'm not gon diss you on the internet
    Cause my mama taught me better than that

  9. #9
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    The code that you have shown is all correct. The other code on the test page has a second part for Linklistmaker that is causing the problem.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  10. #10
    SitePoint Enthusiast
    Join Date
    Feb 2008
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I know... My head is hanging with shame. I should have posted the entire script in the first place. I'll buy you a beer next time I'm in Christchuch to make up for wasting your time with an incomplete script.
    You know I'm not gon diss you on the internet
    Cause my mama taught me better than that

  11. #11
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    That sounds great, and perhaps I'll buy one for you too.

    It's great to know that you have things sorted there now.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •