SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2011
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I get the value from the .html() in jquery?

    Basically I have a form and a script that loops through all fields(inputboxes, textarea, radio buttons, etc.) within the form. One field is particularly special because I am using flexbox (http://www.fairwaytech.com/flexbox/flexbox-demos/), which is created by using a empty div tag that is defined in jQuery(function($){}). Since my script loops through all fields except the flexbox field because it is a div, I figured I could create a hidden field where the value of that div could be placed in. The script would then loop through all fields + that hidden field containing the value from the div. My problem is getting the value from that div.

    Now if I did this in my code

    Code:
    jQuery(function($){
    	    $('#location').flexbox(countries, {  
    
        onSelect: function() {  
    
                    $('#location').html(this.value);	       
    
    		}
    
        }); 
    })
    The div containing flexbox will be replaced by the value of the selected item in flexbox. How do I assign the "this.value" to a variable to be put into the hidden field?

    For testing purposes, if I do

    Code:
    jQuery(function($){
                 var flexboxValue;
    	    $('#location').flexbox(countries, {  
    
        onSelect: function() {  
    
                    flexboxValue = $('#location').html(this.value);	       
    
                     for (x in flexBoxValue){
                         document.write(x + "<br />");
                     }
    		}
    
        }); 
    })
    it would display a long list of properties. All I need is that selected value from flexbox, not the objects properties. Document.write(x.val) would give me undefined as well as all the listed properties.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,713
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ral1239 View Post
    The div containing flexbox will be replaced by the value of the selected item in flexbox. How do I assign the "this.value" to a variable to be put into the hidden field?
    It seems that it would be as easy as doing:

    $('#hiddenField').val(this.value);
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2011
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, Thank you!

    It was really that simple..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •