-2
<script src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
   var usr = 'charliesheen';

   function changeusr()
   {
      usr = document.getElementById("usrText").value;
      updatetwitter();
   }

   var twitter;
   newtwitter();

   function updatetwitter()
   {
      twitter.render().setUser(usr).start();
   }

   function newtwitter()
   {
     twitter =
     new TWTR.Widget({
       version: 2,
       type: 'profile',
       rpp: 4,
       interval: 6000,
       width: 200,
       height: 300,
       theme: {
         shell: {
         background: '#ffffff',
         color: '#367542'
       },
       tweets: {
          background: '#e3dfe3',
          color: '#000000',
          links: '#110af5'
       }
     },
     features: {
        scrollbar: false,
        loop: false,
        live: false,
        hashtags: true,
        timestamp: true,
        avatars: false,
        behavior: 'all'
      }
    }).render().setUser(usr).start();
}
</script>
<br/>
Change user:
<input name="usrText"/>
<button onclick="changeusr()">Go</button>

The results I see are: It loads fine. When I enter a new username and click "go" it may or may not reload the twitter widget, and the link "join the conversation" points to the correct url. I'd like it to reload the url with the new user entered. I'm a complete javascript noob. Thanks in advance.

6
  • Can you create this on jsbin or jsfiddle? Commented Mar 4, 2011 at 21:10
  • @Michael Haren works the same in jsfiddle... Commented Mar 4, 2011 at 21:25
  • Right...can you share it so I don't have to create it myself? Commented Mar 4, 2011 at 21:35
  • @Michael Haren jsfiddle.net/roviuser/aH7sY try that... not sure if it'll work. the jsfiddle "share" drop down doesn't work. maybe it's because i'm in IE7 Commented Mar 4, 2011 at 21:50
  • @roviuser - I updated my answer. If you have the "live" feature set to "true", it seems to work a little better, but I have not been able to get it to re-draw the header. Commented Mar 4, 2011 at 22:02

1 Answer 1

4

Your input needs an id:

<input id='usrText' name="usrText"/>

Internet Explorer will return elements by name from "getElementById()", but that is simply legacy broken behavior and it's not imitated by other browsers.

edit — an update:

There doesn't appear to be much documentation for that widget thing. Things work somewhat better if you set the "live" feature to true. Also, when you update the user, you have to zap an internal variable on the widget:

function updatetwitter()
{
  twitter._profileImage = null;
  twitter.setUser(usr).render().start();
}

Here is the jsfiddle if you'd like to see it.

Sign up to request clarification or add additional context in comments.

7 Comments

While this may be true, this isn't the problem. I am successfully getting the text from the box. the problem is with re-rendering the widget.
I beg to differ - if the input doesn't have an "id" value, then (except in IE) the call to "getElementById()" will return null.
I edited the comment to say "successfully" instead of "correctly" - while it may not be correct, I AM getting the text from it, and the problem is with re-rendering the widget. You can see it in action here: somewhatbiased.blogspot.com - you can tell that I am getting the text, because while most of the widget fails to load, the link at the bottom of the widget that says "join in on the conversation" points to the text entered...
On that page, your <input> element does have an "id" value :-)
ah - well the problem is clearly inside that Twitter widget thing; it's like it works by calling "document.write" or something.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.