0

http://lrroberts0122.github.com/DWS/lab6/level-3/index.html

http://lrroberts0122.github.com/DWS/lab6/level-3/js/script.js

What I'm trying to do: For the field "Your Profile Link" I am trying to make it so that the text entered dynamically appears after "fitandawesome.com/" so that it shows the user's profile link.

Okay, so this is what I've added, and according to sources, this should work. Why doesn't it? If anyone could help me out I'd be greatly appreciate it. I'm not too savvy with JavaScript!

Update Okay, so I got it to work by putting the script in the body instead of the head. I'm still having and issue however, because it's kind of "laggy." It doesn't display the last letter typed. Anyone know how to fix this?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Lindsay
  • 877
  • 2
  • 12
  • 30

1 Answers1

1

You need to call the script.js once the DOM has loaded. There's 2 ways of doing this:

  1. link your script.js at the end of the body.
  2. Use jQuery event listener to run the code once the page has loaded.

.

$(function(){
    $('#profile_link').keypress(function(){
        $('#preview').text($(this).val());
    });
})
kumiau
  • 714
  • 3
  • 17
  • This works, and I added the function bit before the script, however it's being laggy. It's not displaying the last letter typed. – Lindsay Oct 14 '12 at 12:41
  • Do you by any chance know why? – Lindsay Oct 14 '12 at 12:43
  • keypress() fires before the text is entered, to fix this i used keyup. http://jsfiddle.net/MNWKV/1/ (reference: http://stackoverflow.com/questions/8795283/jquery-get-input-value-after-keypress) – kumiau Oct 14 '12 at 12:45
  • Oh I see! I was using keypress, not keyup! (I haven't learned these things yet, obviously. Haha). Well thank you so much! :) I appreciate your help! (And you have a beautiful website, by the way.) – Lindsay Oct 14 '12 at 12:49