• Resolved Sébastien Dumont

    (@sebd86)


    I am trying to complete a plugin I am developing but I am a little stuck on a small piece of code that I have written in jQuery and was wondering if any one can see what I am doing wrong.

    When the text input field for width or height the value is suppose to update a previously set var.

    I have added an alert to see if it has changed the results and see that it is not changing from the default set values.

    Can any one help me correct this please.

    It would be most appreciated, thank you.

    jQuery(document).ready(function(){
    
    	var sizeWidth = 480; // Default for width.
    	var sizeHeight = 320; // Default for height.
    
    	jQuery('input[name="width"]').keyup(function(){
    		var value = jQuery(this).val();
    		jQuery(this).text(value);
    		jQuery(sizeWidth).val(value);
    		alert(sizeWidth);
    	}).keyup();
    
    	jQuery('input[name="height"]').keyup(function(){
    		var value = jQuery(this).val();
    		jQuery(this).text(value);
    		jQuery(sizeHeight).val(value);
    		alert(sizeHeight);
    	}).keyup();
    
    });
Viewing 7 replies - 1 through 7 (of 7 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Anything revealing from your browser’s console log?

    Thread Starter Sébastien Dumont

    (@sebd86)

    No errors show in firebug in firefox. When the alert pops up it shows the value but not the updated value if different from the default set.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Can you put something into jsFiddle so we can see your issue?

    Thread Starter Sébastien Dumont

    (@sebd86)

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I don’t get what you’re trying to do, but you’re not assigning the variable another value, so it just uses its original value.

    Moderator bcworkz

    (@bcworkz)

    I don’t see where you’re going with this. If the sizes are for a HTML element, you should be setting the element’s attribute with jQuery(this).val();. If it’s for something else, perhaps an image, why not just sizeWidth = jQuery(this).val();?

    Thread Starter Sébastien Dumont

    (@sebd86)

    I have figured it out and it now works. Thanks anyway.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘jQuery Value not updating on keyup’ is closed to new replies.