Put function in external file?

Discussion in 'JavaScript' started by bellcom, Feb 7, 2014.

  1. #1
    I wrote some code to use on ebay ads, I just paste the html into the editor window used for creating ads on ebays website. I was able to include an external css file from another site and at the bottom of page I have javascript that controls tabbed content in the content area.

    Here is what the ad looks like:
    http://virtualgeorge.info/ultra/ebay.htm

    I was wondering if I can put the javascript function that have in the code in an external file?
    When I paste the code into the box, sometimes by end brackets on the <script> tags get changed to
    &lt;script&gt; for some reason?

    The code for the tabbed content that I included in the html but I would like to put into an external file is this:

    <script type="text/javascript">
    function tab(tab) {
    document.getElementById('description').style.display = 'none';
    document.getElementById('payment').style.display = 'none';
    document.getElementById('shipping').style.display = 'none';
    document.getElementById('terms_of_sale').style.display = 'none';
    document.getElementById('about_us').style.display = 'none';
    document.getElementById('li_tab1').setAttribute("class", "");
    document.getElementById('li_tab2').setAttribute("class", "");
    document.getElementById('li_tab3').setAttribute("class", "");
    document.getElementById('li_tab4').setAttribute("class", "");
    document.getElementById('li_tab5').setAttribute("class", "");
    document.getElementById(tab).style.display = 'block';
    document.getElementById('li_'+tab).setAttribute("class", "active");
    }
    </script>
    Code (markup):
    Any suggestions much appreciated!!
     
    bellcom, Feb 7, 2014 IP
  2. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #2
    I doubt eBay would allow you to insert JavaScript as it could be a security problem. The reason you are seeing your tags changed is because they are converting the tags to their entity which will make the browser not render it as actual code.
     
    HuggyStudios, Feb 7, 2014 IP
  3. bellcom

    bellcom Well-Known Member

    Messages:
    220
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    120
    #3
    The code doesn't always change and the page does show fine.
    Seems like it does it when using IE instead of Firefox or maybe its when changing the editor from standard mode to html mode and making minor changes is when it converts the code.
    If I just paste in the code and save its fine.

    Maybe I could do the tabbed content with css instead of javascript?
     
    bellcom, Feb 7, 2014 IP
  4. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #4
    You are correct. Once you switch from standard mode to html mode and then make a change and saving, it will convert all applicable characters to HTML entities (including < and >), regardless of the browser.

    The way I do it is that I make the modifications on html mode, then before saving switching back to standard mode so all my HTML code stays intact.
     
    ThePHPMaster, Feb 12, 2014 IP