Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created January 13, 2009 03:12
Show Gist options
  • Save tenderlove/46304 to your computer and use it in GitHub Desktop.
Save tenderlove/46304 to your computer and use it in GitHub Desktop.
require 'johnson'
require 'rubygems'
require 'nokogiri'
doc = Nokogiri::HTML(<<-eohtml)
<html>
<head>
<script>
function populateForm() {
var select = document.getElementsByTagName("select").item(0);
var colors = ['red', 'green', 'blue'];
// Populate drop down
for(var i = 0; i < colors.length; i++) {
var color = colors[i];
var option = document.createElement('option');
var text = document.createTextNode(color);
option.appendChild(text);
option.setAttribute('value', color);
select.appendChild(option);
}
// Change the form action
var form = document.getElementsByTagName("form").item(0);
form.setAttribute('action', 'http://tenderlovemaking.com/');
form.setAttribute('method', 'post');
}
</script>
</head>
<body onload="populateForm()">
<form>
<select id="select_tag" name="fave_color">
</form>
</body>
</html>
eohtml
rt = Johnson::Runtime.new
rt['document'] = doc
rt.evaluate(doc.at('script').content)
rt.evaluate(doc.at('body')['onload'])
puts doc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment