Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
change value src in html page

I want to change the image size or any value in HTML page by this way dropdown list.

this is my code:

<html>
  <head>

  </head>
  <body>

   <select id="selectbox" name="">
              <option value="empty"></option>
              <option value="firstSize">1</option>
              <option value="SecondSize">2</option>
</select>
<br><br>

    <img src="https://www.ask.com/wp-content/uploads/sites/3/2022/02/PowerOfDogPromo.jpeg?resize=768,432">
</div> 

  </body>
</html>

If selecting 1 from selectbox I want to change the size of the image above src to "https://www.ask.com/wp-content/uploads/sites/3/2022/02/PowerOfDogPromo.jpeg?resize=400,200"

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This will work, you can change the button's text if you want

function check(){
var val = document.getElementById("selectbox").value
var pic =  document.getElementById("img")
if(val==="firstSize"){
pic.setAttribute('src','https://www.ask.com/wp-content/uploads/sites/3/2022/02/PowerOfDogPromo.jpeg?resize=400,200')
}
}
<html>
  <head>

  </head>
  <body>

   <select id="selectbox" name="">
              <option value="empty"></option>
              <option value="firstSize">1</option>
              <option value="SecondSize">2</option>
</select>
<button onclick="check()">Check</button>
<br><br>
    <img src="https://www.ask.com/wp-content/uploads/sites/3/2022/02/PowerOfDogPromo.jpeg?resize=768,432" id="img">
</div> 

  </body>
</html>

OR you can do

function check(){
var val = document.getElementById("selectbox").value
var pic =  document.getElementById("img")
if(val==="firstSize"){
pic.setAttribute('src','https://www.ask.com/wp-content/uploads/sites/3/2022/02/PowerOfDogPromo.jpeg?resize=400,200')
}
}
<html>
  <head>

  </head>
  <body>

   <select onchange="check()" id="selectbox" name="">
              <option hidden value="empty"></option>
              <option value="firstSize">1</option>
              <option value="SecondSize">2</option>
</select>

<br><br>
    <img src="https://www.ask.com/wp-content/uploads/sites/3/2022/02/PowerOfDogPromo.jpeg?resize=768,432" id="img">
</div> 

  </body>
</html>

what's different in snippet 1 and 2 is in number 2 there's no button, when you click an option it will change and you cannot select the empty value

you can combine 1 and 2 using hidden and no button but if it breaks just post in this question/post

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!