Cant get a text box to make an image bigger Javascript

i got this question in college and dont know what to do to get it work

I don’t see any question there…

Sorry forgot to add it, there it is


There still doesn’t seem to be any question there.

You said that you got a question. What question do you have about it? <= a question

I dont know how to finish the code off, the screenshot is my attempted of the question i replied with.

i know i have height for both my function the changed it and it doesn’t work

I’m guessing this is a task assigned for the learning experience. i.e. in list form:

  1. Create a form
    • with an image,
    • a button called “Resize”
    • and a textbox.
      • Use the textbox to take in a number.
  2. When the user clicks the “Resize” button,
    1. get the number from the textbox
    2. and set the width and height of the image to that value (in pixels).

Step one is HTML, step two is JavaScript. In order for the JavaScript to work without out any unexpected bugs it is important to have good HTML.

Sorry, but I don’t have the patience ATM to transcribe the HTML from the image into text so it can be worked with. If you paste the HTML for that page into the validator

you will get error and warning messages indicating what should be fixed before proceeding.

Please do the best you can with that and post the improved HTML (not a image please) here when done.

1 Like

Thats what i have so far

<!doctype html>
<html lang="en">
<meta charset="utf-8">
    <script src="question1.js"></script>


<input type="button" id="but1" ondblclick="changeTextbox()" value="change"/>
<form name="resize">
    width:<input type="text" id="Lsize" size="3"/>
    height:<input type="text" id="Wsize" size="3">
    <img src="" alt="filler img" >




theres the js

function changeTextbox()
	var x = document.getElementById('size'); = Lsize + "px"; = Wsize + "px";

I see you have two text inputs, one for height and one for width. My read of the specifications is “a textbox [sic text input] … the number from the textbox” is that there should be only one not two text inputs. (by definition the dimensions would be a square)

It might be acceptable to have separate text inputs, but doing so introduces a bit of complexity that might be better to avoid for the time being.

I recommend you try to be more attentive to naming, inconsistencies can and have been known to cause problems for many devs many times. eg.

  • button value “change” instead of “Resize” likely not that important
  • an input labeled width with an id “Lsize”
  • an input labeled height with an id “Wsize”

“width” - “L” and “height” - “W” would confuse me. Indeed, the JavaScript
there is no HTML element with an id “size”, anyway, = Lsize + "px"; = Wsize + "px"; 

the style height is being assigned the value of a nonexistent “Lsize” variable, I assume the intention is connected to the width input with the id Lsize.

the style width is being assigned the value of a nonexistent “Wsize” variable, I assume the intention is connected to the height input with the id Wsize.

But don’t worry about all that for now. If you change the HTML to have only a single text input (because it is for a square I would label it “side”, but use what makes sense to you)

To “get” the value of the input and “get” the image element, it could then be something like this

side: <input type="text" id="side" value="" /> 
<img ... id="test_image" /> 
const size = document.getElementById('side'); 
const image = document.getElementById('test_image'); = size.value + "px"; = size.value + "px"; 

Does that make sense so that you can see what is being done?


Ya thanks makes sense

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.