scrpaingnoob
scrpaingnoob

Reputation: 157

javascript variable to ejs

I'm trying to get a value from text field and pass it to ejsso that it can render the variable and display it on a fly. I'm using jquery steps and on first step i enter my name. I would want to display that name on the second step. Here is the javascript code:

var form = $("#form").show();
$("#form").steps({
    headerTag: "h3",
    bodyTag: "section",
    transitionEffect: "slideLeft",

onStepChanged: function (event, currentIndex, priorIndex){
if (priorIndex ==  1)
   {
     fname = $('#fname').val();
   } 
});

I would want this fname to be displayed on next step or any view. So any help on passing the variable from javascript logic to ejs would be highly valuable.

Upvotes: 1

Views: 796

Answers (1)

joepin
joepin

Reputation: 1548

I'm not certain I understand the question, but EJS is a templating language that is generally processed before JavaScript runs. For example, it is commonly used in server side rendering; the server receives a request, processes the EJS template, and returns HTML. EJS is generally a couple of steps before JavaScript, and the two don't interact with each other. Thus, there is no way to pass a JavaScript variable's value to an EJS variable.

You can, however, use JavaScript to update the value on the next step. So, you can simply look up an element in the DOM, and update its text value in your onStepChanged function. You can do so with jQuery as follows:

$("#nameContainer").text($('#fname').val());

Upvotes: 1

Related Questions