PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Change image size live when form field entered

  1. Following on from some helpful advice on this forum, I have tried to develop a solution to a problem. Basically, when a user enters their bespoke widths into two seperate form fields (#input_9_2 and #input_9_3) I want an image or div layer, or table, to change shape in relation to the entered field entry. So if say, a user enters 20cm in field one and 300cm in field two, the image/div/cell will automatically before their eyes show that shape (using cm as pixels - this 20 px wide x 300px high). This is the code I have been using but it just isnb't working - I have no doubt my argument / syntax is wrong but can anyone help - I'm now three days into this and have tried very hard to sort myself. Many thanks.

    -------

    <img class="sbimg" id="sbimg" src="/wp-content/uploads/2012/06/AAF-Splashback-Black-Gloss-Splashback-Full-No-Handle-200x200.jpg">
    <script>
    $(function width(){
      $('#input_9_2').keydown(function(){
        setTimeout(function() {
          $('#input_9_2').val();
        }, 50);
      });
    });
    $(function height(){
      $('#input_9_3').keydown(function(){
        setTimeout(function() {
         $('#input_9_3').val();
        }, 50);
      });
    });
    var photo = document.getElementById('sbimg');
    var photoWidth = width();
    var photoHeight = height();
    photo.width = photoWidth;
    photo.height = photoHeight;
    </script>
    Posted 12 years ago on Wednesday August 1, 2012 | Permalink
  2. Can you post a link to this live somewhere so we can take a look at it? Maybe it's something simple that more eyes will catch.

    Posted 12 years ago on Wednesday August 1, 2012 | Permalink
  3. Hi Chris - link to page here, just select 'custom sizes' to see the section I'm talking about: http://www.thesplashbackfactory.com/splashback-products/black-steel-splashback-12mm

    Posted 12 years ago on Thursday August 2, 2012 | Permalink
  4. Thanks for that link. When I access that page I get this JavaScript error:

    Timestamp: 8/2/2012 6:15:43 AM
    Error: ReferenceError: width is not defined
    Source File: http://www.thesplashbackfactory.com/splashback-products/black-steel-splashback-12mm
    Line: 210

    Let me look into that a little bit and see what I can find out.

    Posted 12 years ago on Thursday August 2, 2012 | Permalink
  5. Maybe width and height should be defined up front, so that before the keydown event is captured, there will still be a width and height value? Define them before the function, then rely on the function to change them based on the data entry? Is there a default size at which the image starts?

    Posted 12 years ago on Thursday August 2, 2012 | Permalink
  6. Hi Chris - I've changed it to make it default to 200 h and 200 w. Thank you so much for helping with this - I am so desperate for it now!

    Posted 12 years ago on Thursday August 2, 2012 | Permalink
  7. new code:

    <img class="sbimg" id="sbimg" src="/wp-content/uploads/2012/06/AAF-Splashback-Black-Gloss-Splashback-Full-No-Handle-200x200.jpg" width="200" height="200">
    <script>
    $(function width(){
      $('#input_9_2').keydown(function(){
        setTimeout(function() {
          $('#input_9_2').val();
        }, 50);
      });
    });
    $(function height(){
      $('#input_9_3').keydown(function(){
        setTimeout(function() {
         $('#input_9_3').val();
        }, 50);
      });
    });
    var photo = document.getElementById('sbimg');
    var photoWidth = width();
    var photoHeight = height();
    photo.width = photoWidth;
    photo.height = photoHeight;
    </script>
    Posted 12 years ago on Thursday August 2, 2012 | Permalink
  8. Is that working for you now or do you need to me to take a look again? I forget where we were with this one.

    Posted 12 years ago on Saturday August 4, 2012 | Permalink