Here is a chunk of some my Javascript code that sends the information back to the Ruby:
function callRuby(ActionName)
{
// Basic Options
var s0 = document.getElementById("rooftype");
var v0 = s0.options[s0.selectedIndex].value;
var i1 = document.getElementById("pitch");
var v1 = i1.value;
var i2 = document.getElementById("overhang");
var v2 = i2.value;
var i3 = document.getElementById("birdcut");
var v3 = i3.value;
var i4 = document.getElementById("rd");
var v4 = i4.value;
var i5 = document.getElementById("ply");
var v5 = i5.value;
var i6 = document.getElementById("rbd");
var v6 = i6.value;
var i7 = document.getElementById("rbw");
var v7 = i7.value;
var i8 = document.getElementById("hbd");
var v8 = i8.value;
var i9 = document.getElementById("hbw");
var v9 = i9.value;
var i10 = document.getElementById("vbd");
var v10 = i10.value;
var i11 = document.getElementById("vbw");
var v11 = i11.value;
var i12 = document.getElementById("rafter_spacing");
var v12 = i12.value;
var s13 = document.getElementById("framingoption");
var v13 = s13.options[s13.selectedIndex].value;
if (licensemode == 'lt')
{
if (v13 == 'YES')
{
v13 = 'NO';
s13.value = 'NO';
}
}
var s14 = document.getElementById("advroofoptions");
var v14 = s14.options[s14.selectedIndex].value;
var i15 = document.getElementById("assy_name");
var v15 = i15.value;
document.getElementById("submitstatus").innerHTML = 'Updating Assembly...';
var paramstring1 = v0 + '|' + v1 + '|' + v2 + '|' + v3 + '|' + v4 + '|' + v5 + '|' + v6 + '|' + v7 + '|' + v8 + '|' + v9 + '|' + v10 + '|' + v11 + '|' + v12 + '|' + v13 + '|' + v14 + '|' + v15;
var query1 = 'skp:GET_ROOF_EDIT@' + paramstring1;
window.location.href = query1;
if (v14 == 'YES')
{
// setTimeout(function(){
callRubyADV('Update');
// },50);
}
// setTimeout(function(){
callRubyexec('Submit');
finalizechange();
// },750);
}
function callRubyADV(ActionName)
{
// Advanced Options
var s1 = document.getElementById("roofsheath_option");
var v1 = s1.options[s1.selectedIndex].value;
var i2 = document.getElementById("roofsheath_thk");
var v2 = i2.value;
var s3 = document.getElementById("roofsheathmat");
var v3 = s3.options[s3.selectedIndex].value;
var s4 = document.getElementById("roofclad_option");
var v4 = s4.options[s4.selectedIndex].value;
var i5 = document.getElementById("roofclad_thk");
var v5 = i5.value;
var i6 = document.getElementById("roofcladext");
var v6 = i6.value;
var s7 = document.getElementById("roofcladmat");
var v7 = s7.options[s7.selectedIndex].value;
var s8 = document.getElementById("fascia_option");
var v8 = s8.options[s8.selectedIndex].value;
var s9 = document.getElementById("fascia_type");
var v9 = s9.options[s9.selectedIndex].value;
var i10 = document.getElementById("fascia_width");
var v10 = i10.value;
var i11 = document.getElementById("fascia_depth");
var v11 = i11.value;
var s12 = document.getElementById("soffitcut");
var v12 = s12.options[s12.selectedIndex].value;
var s13 = document.getElementById("ridgecap_option");
var v13 = s13.options[s13.selectedIndex].value;
var s14 = document.getElementById("gutter_option");
var v14 = s14.options[s14.selectedIndex].value;
var paramstring3 = v1 + '|' + v2 + '|' + v3 + '|' + v4 + '|' + v5 + '|' + v6 + '|' + v7 + '|' + v8 + '|' + v9 + '|' + v10 + '|' + v11 + '|' + v12 + '|' + v13 + '|' + v14;
var query3 = 'skp:GET_ROOF_EDIT_ADV@' + paramstring3;
window.location.href = query3;
if (v8 == 'YES')
{
// setTimeout(function(){
callRubySOF('Update');
// },100);
}
if (v14 == 'YES')
{
// setTimeout(function(){
callRubyGUT('Update');
// },150);
}
if (v13 == 'YES')
{
// setTimeout(function(){
callRubyHR('Update');
// },200);
}
}
As you can see I am sending my parameters back to Ruby in multiple calls since I don’t want to send it all via one large call which might become problematic since there are a lot of parameters.
I’m utilizing timers (setTimeout) to allow for the asynchronous behavior needed between Ruby and the HTML/Javascript. Without the timers (I’ve commented them out in this example) the data does not get all transmitted before the Ruby resumes and completes the operation however I am probably doing something wrong here, it wouldn’t surprise me.