1

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.

1 Answer 1

1

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());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.