Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8967183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:11:20+00:00 2026-06-15T17:11:20+00:00

I have a javascript function but if I use it, it doesn’t work. If

  • 0

I have a javascript function but if I use it, it doesn’t work. If I use the same code without the function on my html it does work.

<script type="text/javascript">
function jon(str) {
    id = 'j'+str;
    getElementById(id).setAttribute('class', '');
}
function jover(str) {
    id = 'j'+str;
    getElementById(id).setAttribute('class', 'hide');
}
</script>

<form id="lijst" action="" method="POST" onSubmit="return formOK();">
    <table>
        <tr onMouseOver="getElementById('jtitle').setAttribute('class', '');" onMouseOut="getElementById('jtitle').setAttribute('class', 'hide');">
            <th>* Title</th>
            <td><input type="text" name="title" /></td>
            <td id="jtitle" class="hide">Vul een film of serie titel in.</td>
        </tr>
        <tr onMouseOver="jon('type');" onMouseOut="jover('type');">
            <th>* Type</th>
            <td><select name="type"><option value="film">Film</option><option value="serie">Serie</option></select></td>
            <td id="jtype" class="hide"></td>
        </tr>

The title does work, but the type doesn’t work.
The console says the getElementById() isn’t defined. I tried to put var id = '' for the functions but that doesn’t work.

So how can I fix that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:11:21+00:00Added an answer on June 15, 2026 at 5:11 pm

    You need the prefix document.:

    document.getElementById(id).setAttribute(...);
    

    The getElementById method is defined on the document object. In order to call a method on any object you need to use the object on which it is defined, followed by a dot . and the method name. For example:

    document.getElementById()
       |    ^       |
       |            |
       |            |
    [object]    [method]
    

    The only exception is for the window object, where that is not required when you define a function or variable on it; you can use it as if it were free-standing. But in actuality all global variables in particular are on the window object. This can be caused by accidentally omitting the var keyword when creating a variable. For example:

    x = 5;
    

    Assume that a variable x has not been previously defined. Since x was not created with the var keyword, it’s put on the window object. We can check it in the console:

    >> window.x;
    
     : 5
    

    This can lead to sticky situations in that it can conflict with another x variable declared in an outer scope. That’s why it’s always important to define with var. There shouldn’t be a reason not to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in .gsp file i have javaScript function <script type=text/javascript> function getCurrentItemNumber(){ return document.getElementById('item_itemNumber').innerHTML.substr(6); }
I have this javascript: <script type=text/javascript> $(document).ready(function () { $('#social-share').dcSocialShare({ buttons: 'twitter,facebook,linkedin,digg,stumbleupon,delicious,pinterest,buffer,print,email', offsetLocation: 0,
I have a javascript function, that works fine if it's anonymous but stops working
I have a div, which onclick calls a javascript function. But it fails to
I have created a signup page on my site, but the javascript validation function
Function constructors are able to create objects in javascript but I have a more
I have Javascript function defined in the main index.html file. One part of this
I have a function in JavaScript which is included in the main HTML document
I have a JavaScript function that I use to call the Facebook API and
I have a javascript function that posts data to a validation script and grabs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.