473,320 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Embbeded Ruby (erb) from Javascript

I am wondering if it is possible to set embedded ruby variables in javascript. I've tried but to no avail. I'm thinking the javascript block won't recognize the <% %> erb tags.

What I want to do is basically call a javascript function from an onclick="setField('first_name')"

function setField(name)
{
<% fieldName = name %>
}

I don't think it's possible, because you are trying to put a javascript variable (name) into ruby, which I don't think it likes. Is there any possible way to do this. Or a confirmation that this cannot be done would be reassuring.

Thanks in advance
May 11 '06 #1
2 5980
Banfa
9,065 Expert Mod 8TB
I would say (remembering that until I saw this post I thought Ruby was and W3C DTD for adding text along side main text to indicate pronouciation, which is is see here) looking that this code that you Ruby code is running as server side script (most <% %> scripts run server side) and that the Javascript is probably (in the absence of anything indicating otherwise) running client side.

This means your Ruby script will have been executed before the Javascript has even been downloaded to the client.

Additionally as you posulate it is very unlikely that Ruby would be able to deal with a variable name from Javascript the reverse of this can be done though (set a javascript variable to the value of a Ruby variable, I am going to give a PHP example since I know PHP and not Ruby
[php]
function PrintSomething()
{
var ThingToPrint;

ThingToPrint = "<?php print( $PhpVariable ); ?>";

writeln( ThingToPrint );
}
[/php]

Since the php runs server side the short php script is replace by its output which is the value of $PhpVariable. When it gets to the client the javascript runs and picks up this value.

HTH
May 11 '06 #2
Beny
1
Hello,

I'm also looking for ERB javascript solution. And I've found ERB JS tutorial about this with google.
Jan 11 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
10
by: Neal | last post by:
I'm beginning some experiments with Ruby in XHTML 1.1. I'm finding very odd results which surprise me. I'm using a PHP snippet which serves application/xml+xhtml and XHTML 1.1 to those browsers...
65
by: Amol Vaidya | last post by:
Hi. I am interested in learning a new programming language, and have been debating whether to learn Ruby or Python. How do these compare and contrast with one another, and what advantages does one...
1
by: walkerhunter | last post by:
I have the three embedded Ruby(erb) check_boxes below: Patient #1<%= check_box("patient", '1', {}, "yes","no") %></br> Patient #2<%= check_box("patient", '2', {}, "yes","no") %></br> Patient...
26
by: brenocon | last post by:
Hi all -- Compared to the Python I know and love, Ruby isn't quite the same. However, it has at least one terrific feature: "blocks". Whereas in Python a "block" is just several lines of...
12
by: Tony Belding | last post by:
I'm interested in using an off-the-shelf interpreted language as a user-accessible scripting language for a MUCK. I'm just not sure if I can find one that does everything I need. The MUCK must be...
9
by: Erwin Moller | last post by:
Hi Group, This may seem a odd question in a PHP group, but I think this might be a good place to ask since I am mainly a PHP coder these days that maybe starts with Ruby. Situation: A client...
1
by: maildmz | last post by:
Goodafternoon, I have got a minimum Mongrel instance running (see ruby code) and i am hitting it with an Ajax request using Prototype. (see javascript code) I get the 'onLoading' event, but...
2
by: David | last post by:
Hey can anyone help me convert a javascript array into a ruby array. Ive been struggling with this since friday to no avail. This is the function with the ajax.request call that is supposed to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.