Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

changing value on submit button not working.

I have a working version of this assignment, to which I've added the extras in the video. The below code does disable the button while loading the images, and re-enable the button after loading. However the button text doesn't change. What am I missing?

$(document).ready(function() {
    $('form').submit(function(evt) {
        evt.preventDefault();

        var $searchField = $('#search');
        var searchTerm = $searchField.val();
        var $submitButton = $('submit');

        $searchField.prop('disabled', true);
        $submitButton.prop('disabled', true).val('Searching...');
        // the AJAX part
        var flickerAPI =
            'http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?';
        var flickrOptions = {
            tags: searchTerm,
            format: 'json'
        };

        function displayPhotos(data) {
            var photoHTML = '<ul>';
            $.each(data.items, function(i, photo) {
                photoHTML += '<li class="grid-25 tablet-grid-50">';
                photoHTML += '<a href="' + photo.link + '" class="image">';
                photoHTML += '<img src="' + photo.media.m + '"></a></li>';
            }); // end each
            photoHTML += '</ul>';
            $('#photos').html(photoHTML);
            $searchField.prop('disabled', false);
            $submitButton.attr('disabled', false).val('Search again');
        }
        $.getJSON(flickerAPI, flickrOptions, displayPhotos);
    }); // end click
}); // end ready

1 Answer

Steven Parker
Steven Parker
231,007 Points

You didn't show the HTML part of the code, but I'm guessing you have either a button element or an input element that has the ID of "submit".

So if that's the case, then $submitButton should probably be assigned to "$('#submit')" (with a "#", instead of "$('submit')").