2

Consider:

File script.js,

 function AdaugaComboBox(id, name){
 var select_tag = document.getElementById(id);
 select_tag.innerHTML += "<select name='"+name+"'><option value='0'>Selecteaza autor</option></select><br/>";
 return true;
 }

and file index.html:

<html>
 <head>
 <script src="js/script.js" type="text/javascript"></script>
 </head>
 <body>
 <table>
 <tr>
 <td id="autori">...</td>
 </tr>
 <tr>
 <td>
 <input type="button"
 value="Adauga autor"
 onclick="AdaugaComboBox('autori', 'autori[]')"/>
 </td>
 </tr>
 </table>
 </body>
</html>

The scope of the function is to add a combo box to the specific TD in the TABLE. But when I press the button this error appears:

AdaugaComboBox is not defined

Why?


Update:

!!! I've fixed it. The problem was with another function.

Brian Tompsett - 汤莱恩
5,92772 gold badges64 silver badges135 bronze badges
asked Jan 27, 2010 at 12:30
6
  • 2
    script.js is not included anywhere in your HTML... Commented Jan 27, 2010 at 12:32
  • Where in the document tree is the function defined? Commented Jan 27, 2010 at 12:32
  • The script.js is included in the document and I get the same error. Commented Jan 27, 2010 at 12:40
  • 1
    The code that you have posted works fine for me in Chrome and IE - no errors. If this is a shortened sample of your code, the error must be somewhere else. Commented Jan 27, 2010 at 12:46
  • I bet your script.js file isn't in a "js" sub directory, because it works fine. Commented Jan 27, 2010 at 12:50

3 Answers 3

4

If the script is included in your HTML, then it's possible that you don't have the path correct based on the location of the HTML file. Check with Firefox/Firebug to make sure that the JS file is being downloaded correctly.

answered Jan 27, 2010 at 12:46
Sign up to request clarification or add additional context in comments.

Comments

1

Your HTML should be:

<html>
<head>
 <script src="script.js" type="text/javascript"></script> 
</head>
<body>
<table>
<tr>
 <td id="autori">...</td>
</tr>
<tr>
 <td>
 <input type="button" value="Adauga autor" onclick="AdaugaComboBox('autori', 'autori[]')"/>
 </td>
</tr>
</table>
</body>
</html>
answered Jan 27, 2010 at 12:33

2 Comments

The script.js is included in the document and I get the same error.
Your script.js file must not be in a sub-directory called "js" then, because the code works fine.
1

You have to put a reference to the script.js file.

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

Skilldrick
71.2k37 gold badges183 silver badges231 bronze badges
answered Jan 27, 2010 at 12:32

1 Comment

The script.js is included in the document and I get the same error.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.