3 Replies - 395 Views - Last Post: 20 January 2012 - 10:41 AM

Topic Sponsor:

#1 C_coder  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 25-May 11

href can open the javascript on the header

Posted 20 January 2012 - 07:14 AM

Hey,

I have a small question.

I created a javascript in my page, and it was working fine until i decided to create a seperated file to my javascript.
Now I click in my "button" to have the "action" but nothing is done.

in my header i've putted the src to the javascript file, and in my button I've written the function that I want it to call.

I know I've done an error some where but don't know how to work it around.

Here is the code:
code in the header
<link rel="Javascript" type="text/javascript" src="java.js">


<a href="Javascript:addItem"">ADD</a>



Thanks in advanced

Is This A Good Question/Topic? 0
  • +

Replies To: href can open the javascript on the header

#2 SittingonDucks  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 23-December 11

Re: href can open the javascript on the header

Posted 20 January 2012 - 07:33 AM

Don't use the link tag for Javascript code.

Use the <script> tag, like so:

<script type="text/javascript" src="./java.js"></script>


If that doesn't work, you may want to consider looking into the hierarchy of your files and make sure java.js is in the same directory of the HTML file.
Was This Post Helpful? 0
  • +
  • -

#3 SittingonDucks  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 23-December 11

Re: href can open the javascript on the header

Posted 20 January 2012 - 07:38 AM

And as for that <a> tag.

<a href="Javascript:addItem"">ADD</a>

Do not use the Javascript: preface for that. The better thing to do is to add an onclick attr and an id tag, with the href attr being the #[id]. For example:

<a id="adder" onclick="addItem();" href="#adder">ADD</a>

Was This Post Helpful? 1
  • +
  • -

#4 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 2145
  • View blog
  • Posts: 5,425
  • Joined: 08-June 10

Re: href can open the javascript on the header

Posted 20 January 2012 - 10:41 AM

View PostSittingonDucks, on 20 January 2012 - 03:38 PM, said:

The better thing to do is to add an onclick attr and an id tag, with the href attr being the #[id]. For example:

<a id="adder" onclick="addItem();" href="#adder">ADD</a>

or just omit the href altogether and use CSS to make it look like a link (text-decoration, color, cursor).

though then it doesn’t even need to be an <a>, any other inline-tag will do as well

This post has been edited by Dormilich: 20 January 2012 - 10:42 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1