473,789 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Embbeded Ruby (erb) from Javascript

3 New Member
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="setFie ld('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 6017
Banfa
9,065 Recognized Expert Moderator Expert
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 New Member
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
6578
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 FRICKIN' COOL!!! ***MAN*** that would save me a buttload of work and make my life sooooo much easier!" As opposed to minor differences of this feature here, that feature there. Variations on style are of no interest to me. I'm coming at this from a...
10
2287
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 which accept it, and text/html XHTML 1.0 otherwise. I included a simple Ruby setup, first without using the <rp> elements, then with. My results? O7.23 does not render simple Ruby with the overtext as described in the spec, but does not display...
65
5541
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 language provide over the other? I would like to consider as many opinions as I can on this matter before I start studying either language in depth. Any help/comments are greatly appreciated. Thanks in advance for your help.
1
2761
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 #4<%= check_box("patient", '4', {}, "yes","no") %></br> The HTML output looks like this: Patient #1<input id="patient_1" name="patient" type="checkbox"
26
2731
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 locally-scoped-together code, in Ruby a "block" defines a closure (anonymous function). To avoid confusion let's call them Ruby block-closures. I see them as just a syntax for defining
12
2957
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 able to call the interpreter and execute scripts with it, but the interpreter must also be able to call functions in the MUCK code. And then there's the security issue that really worries me. . . I have to be able to limit what the interpreter...
9
2319
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 of a friend of mine asked me to take over a project done in Ruby. (The original programmer appearantly behaved like an @ss and his client wants to get rid of him.)
1
1812
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 the other events never fire. I am getting the response because I can see the response from the Mongrel server in my net monitor (Firebug). But the events itself never fire (no oncomplete and or onfailure)
2
4502
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 convert the array using JSON, but I keep getting a 422(Unprocessable Entity) error. Im not sure what is wrong. function test() { for(i=1;i<22;i++){ if (document.getElementById(i+'d').className ==
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6765
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.