HTML/HTA set image position to VBScript variable

180 Views Asked by At

So I basically want to make a button that changes an image's, let's say, x position to a VBScript variable in HTML. This is an HTA btw, dunno if it actually changes anything.

<script language = "vbscript">
    Position = 50
</script>

<body>
    <img src = "Something.jpeg" style = "position:relative; top:100px; left:(Position)px;">
</body>

Sorry if I worded this badly...

1

There are 1 best solutions below

0
LesFerch On BEST ANSWER

If you're asking how to change an image's position in an HTA based on user input, then the following code example demonstrates how to do that. Note that no button is required. As soon as new values are entered (and you tab to another element or click in the blank space) the image moves.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" http-equiv="X-UA-Compatible" content="IE=9">
<script language = "vbscript">
  Sub window_onLoad
    xPos.value = 50
    yPos.value = 100
    SetPosition
  End Sub
  Sub SetPosition
    Pic1.style.top = yPos.value & "px"
    Pic1.style.left = xPos.value & "px"
  End Sub
</script>
<style>
</style>
</head>
<body>
  <input type=text id=xPos size=3 OnChange=SetPosition()>
  <input type=text id=yPos size=3 OnChange=SetPosition()><br><br>
  <img src="Something.jpeg" id=Pic1 style="position:relative">
</body>
</html>