WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] jQuery Value not updating on keyup (8 posts)

  1. Sebastien D
    Member
    Posted 1 year ago #

    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();
    
    });
  2. Andrew
    Forum Moderator
    Posted 1 year ago #

    Anything revealing from your browser's console log?

  3. Sebastien D
    Member
    Posted 1 year ago #

    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.

  4. Andrew
    Forum Moderator
    Posted 1 year ago #

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

  5. Sebastien D
    Member
    Posted 1 year ago #

  6. Andrew
    Forum Moderator
    Posted 1 year ago #

    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.

  7. bcworkz
    Member
    Posted 1 year ago #

    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();?

  8. Sebastien D
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags