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 7182223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:43:29+00:00 2026-05-28T17:43:29+00:00

var tmp = ; function putItem() { this.innerHTML = <img src = ‘image/+tmp+.png’>; }

  • 0
var tmp = "";

function putItem()
{
    this.innerHTML = "<img src = 'image/"+tmp+".png'>";
}

I also have a td that calls this

<img src = 'images/wood.png' onclick = 'tmp = "wood";'>
<td onclick = "grid1 = tmp; checkEmpty(); putItem(this);">

I tested it by making the "<img src = 'image/"+tmp+".png'>"; a variable and when I returned what the variable was when tmp wasnt an empty string it came out as "<img src = 'image/.png'>" ie it ignored the tmp.

Any help?

I’m trying to make the “Minecraft (c) Crafting Table” for a web dev project

  • 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-05-28T17:43:30+00:00Added an answer on May 28, 2026 at 5:43 pm

    Question changed. Now it seems that the only issue is that you need to use .call to set the this value in putItem.

    <img src = 'images/wood.png' onclick = 'tmp = "wood";'>
    <td onclick = "grid1 = tmp; checkEmpty(); putItem.call(this);">
    


    Original answer

    I assume instead of this…

                  <!--   v---- assign empty string to global grid1 variable -->
    <td onclick = "grid1 = tmp; checkEmpty(); putItem(this);">
    

    You want this…

              <!--     v---- assign "grid1" string to global tmp variable -->
    <td onclick = "tmp = 'grid1'; checkEmpty(); putItem.call(this);">
              <!-- set the value of "this" in "putItem"---^  -->
    

    So now you’re assigning the "grid1" string to the tmp variable, and when you call putItem(), you’re using .call to set its this value.


    That said, instead of using a global variable, why not just pass the string?

    function putItem( str ) {
        this.innerHTML = "<img src = 'image/" + str + ".png'>";
    }
    

    <td onclick = "checkEmpty(); putItem.call(this, 'grid1');">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to generate javascript code similar to this function ParseJsonDate(input) { var tmp
var thumbs = document.getElementsByTagName(img); for (var i=0; i<thumbs.length; i++) { Core.addEventListener(thumbs[i], click, function() {alert(i);});
I have a feeling that the answer to this is easy but I can't
var total = 0; $(.amount).each(function () { var value = $(this).val(); value = (value.length
$.fn.fieldValues = function(successful) { var values = {}; this.each(function() { if(strstr(this.name, '[]', true)) {
I have an array called tmp var tmp = [05, 13, 27]; if an
I keep getting the following errors: /private/var/tmp/phpl3E3lq Warning: imagecreatefromjpeg(/private/var/tmp/phpl3E3lq) [function.imagecreatefromjpeg]: failed to open stream:
in the following code : var benq:Base64Encoder = new Base64Encoder(); benq.encode(force,0,5); var tmp:String =
var y = new w(); var x = y.z; y.z= function() { doOneThing(); x();
Okay first to explain the rules: I need a function that constructs a delegate

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.