0

I am doing dynamic filtering ,but i am unable to do if condition check.

i want to insert targetOS var inside <%if(data[i].ListNames == targetOS ){%>

for the above syntax it is giving "targetOS variable is undefined"

Please help on this.

	$(document).on("change",'.COTSCurrentOSClass', function(e){		
		var selectedOS   = $(this).val();				
		var targetOS =  "OS::From::"+selectedOS;
		
		<%for(var i=0;i<data.length;i++){%>
			<%if(data[i].ListNames == ***targetOS*** ){%>
				<%for(var j=0;j<data[i].Values.length;j++){%> 
				console.log("options are");
				console.log(data[i].Values[j]);
		<%}}}%>

		($(this).parent().parent()).find(".COTSTargetOSClass").append("<option>Select One</option>");
		
	});

2 Answers 2

1

What you want to do is not possible!

This is the sequence of what happens:

1 - In the server, the ejs is rendered to HTML

2 - the HTML is then transferred into the browser

3 - The browser reads and processes the javascript

The JavaScript execution happens at a much later stage than the ejs execution.

Sign up to request clarification or add additional context in comments.

Comments

0

What @fmsf has replied is correct. However, if you know the targetOS value on the server, while rendering the ejs you can do it like this:

define it like this in your ejs file:

var TARGET_OS = "<%= TARGET_OS %>";

Then when you render the page via ejs, pass parameter to it like this:

res.render(url, {TARGET_OS: "Your desired value here"}, function(err, html) {

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.