Poor mans Javascript console

Journal entry
May 26, 2008

Quick and dirty way of testing Javascript live on a website in browsers without Firebug:

<form onsubmit="try {
    $('output').innerHTML = $F('input') + ' => ' + eval($F('input'));
  } catch (e) {
    alert(e)
  }
  return false">
  <div id="output"></div>
  <input id="input" name="input" value="" on="" />
</form>

Requires Prototype, but could probably be rewritten as pure Javascript pretty easily. Could also be turned into a bookmarklet, I guess.

Categories
Selling out
Did you know?
Jakob is an independent web application developer who builds awesome stuff for the web. You can hire him to build awesome stuff for you.

Comments and Trackbacks

Tobias H. Michaelsen May 26, 2008

Without prototype.js would be something like:

var output = document.getElementById('output'); var input = document.getElementById('input'); output.innerHTML = input.value + ' => ' + eval(input.value);

Btw. if you are using prototype.js, you should probably be using the Element#update(value) method instead of using innerHTML

Josef Witchell July 22, 2008

var input = $('input');
$('output').update(input.value + '=> ' + eval(input.value));

Commenting on this entry has been closed.