Resize an image from data entered in a textbox

Francis Gall

ive a form with a image , button and textbox. ive to resize the images height and width to what ever is entered in the textbox, when the button is clicked. My image just disappears when the button is clicked.

heres my code

<!DOCTYPE HTML>
<html>
<head>
    <title>Resize Image</title>
</head>
<body>
<script>
    function resizeimage()
    {
        var theImg = document.getElementById('image');
        theImg.height = size;
        theImg.width = size;
    }
    var size=parseInt(document.getElementById('txtbox'));   
</script>


<form name ="ResizeImage">
<img src = "cookie.jpg" id="image">
</br>
<input type=button value="Resize" onclick="resizeimage()">
</br>
<input type=text id="txtbox"

</form>
</body>
</html>
Stephan Muller

Apart from the HTML problems (please run it through the validator), the main problem is that the part of code that reads the size of the image is outside of the function. On page load, this is what happens.

  1. The function resizeimage() is defined
  2. The var size is set to whatever is in the input at that point
  3. The contents of the page are loaded.

At 2. the input doesn't even exist yet because 3. isn't done yet, so var size is set to undefined. It never changes after that, because the function resizeimage() does not try to read the size of the image again.

Also, document.getElementById returns an element. You will have to read what the user put into it by using it's .value property

Try this:

function resizeimage()
{
    var size=parseInt(document.getElementById('txtbox').value);   
    var theImg = document.getElementById('image');
    theImg.height = size;
    theImg.width = size;
}

Working example: http://jsfiddle.net/KZH5p/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to Encrypt a Data Entered from Textbox?

From Dev

How to Encrypt a Data Entered from Textbox?

From Dev

TextBox completion when data entered in another TextBox

From Dev

Resize image from CSS

From Dev

Javascript or JQuery for showing an image when URL entered into textbox

From Dev

Trying resize an image from drawable?

From Dev

resize image picked from gallery

From Dev

Java resize image from an URL?

From Dev

Resize image from photo album

From Dev

how to resize image from gallery

From Dev

resize image picked from gallery

From Dev

Check checkBox when data is entered in textbox inside a table

From Dev

Keeping the data that user entered in textbox even after submit button is clicked

From Dev

Check checkBox when data is entered in textbox inside a table

From Java

How to pass value entered in textbox to flask in text format from django?

From Dev

How to get entered text from a textbox having no value attribute in selenium

From Dev

How to display entered string from textbox in ordered list in c#?

From Dev

Resize PNG image without losing color data from fully transparent pixels

From Dev

Display data from database to textbox

From Dev

Getting data from database to textbox?

From Dev

Insert data from textbox to database

From Dev

Retrieve Data from DataGridview to textbox

From Dev

How to resize image from url and upload it?

From Dev

Resize an image direct from url using php

From Dev

How to create an image from an InputStream, resize it and save it?

From Dev

Resize image From url objective c

From Dev

Resize image From url objective c

From Dev

How to create an image from an InputStream, resize it and save it?

From Dev

How to resize image from content attribute in CSS

Related Related

  1. 1

    How to Encrypt a Data Entered from Textbox?

  2. 2

    How to Encrypt a Data Entered from Textbox?

  3. 3

    TextBox completion when data entered in another TextBox

  4. 4

    Resize image from CSS

  5. 5

    Javascript or JQuery for showing an image when URL entered into textbox

  6. 6

    Trying resize an image from drawable?

  7. 7

    resize image picked from gallery

  8. 8

    Java resize image from an URL?

  9. 9

    Resize image from photo album

  10. 10

    how to resize image from gallery

  11. 11

    resize image picked from gallery

  12. 12

    Check checkBox when data is entered in textbox inside a table

  13. 13

    Keeping the data that user entered in textbox even after submit button is clicked

  14. 14

    Check checkBox when data is entered in textbox inside a table

  15. 15

    How to pass value entered in textbox to flask in text format from django?

  16. 16

    How to get entered text from a textbox having no value attribute in selenium

  17. 17

    How to display entered string from textbox in ordered list in c#?

  18. 18

    Resize PNG image without losing color data from fully transparent pixels

  19. 19

    Display data from database to textbox

  20. 20

    Getting data from database to textbox?

  21. 21

    Insert data from textbox to database

  22. 22

    Retrieve Data from DataGridview to textbox

  23. 23

    How to resize image from url and upload it?

  24. 24

    Resize an image direct from url using php

  25. 25

    How to create an image from an InputStream, resize it and save it?

  26. 26

    Resize image From url objective c

  27. 27

    Resize image From url objective c

  28. 28

    How to create an image from an InputStream, resize it and save it?

  29. 29

    How to resize image from content attribute in CSS

HotTag

Archive