LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Populating the Dropdown menu/fieldset in HTML page employing LV Web-services.

Hi, 

 

I have created project with LV Web-service with MySQL database. So the chain looks like 

MySQL(table) -> LV Web-Service -> ESP generated HTML Page.

I want to read the MySQL database and generate a list and update the HTML page with the list (array).

 

So far i have been able to generate the list from MySQL and provide an array of string to "Set Many String ESP Variable" function. However, when the HTML page is generated from ESP script. It does not include the full array. I only see the last value on the running HTML page.

 

May be my ESP script is not set to handle the incoming array. what is the proper syntax to handle incoming array in the ESP script? Is it same as JS? or there is a requirement to have for loop?

 

See attached files. 

 

Can anyone help me with the proper code to handle the incoming array in the ESP script file.

 

Regards,

max 

Download All
0 Kudos
Message 1 of 5
(3,302 Views)

Hi Maxout,

 

We have some resources available for ESP scripting. I wanted to pass them on in case you hadn't seen them before.

 

Scripting in LabVIEW Web Services

Embedded Server Pages Reference

 

ESP scripting should be similar to Javascript, Embedded Server Pages Reference above goes into more detail. Let me know if you have any other questions!

0 Kudos
Message 2 of 5
(3,259 Views)

Hi cdaug, 

It took me sometime but i solved the issue. 

Thanks, 

Max. 

0 Kudos
Message 3 of 5
(3,253 Views)

How did you solve it?


Milan
0 Kudos
Message 4 of 5
(3,248 Views)

Hi Milan, 

I followed the example code of Address Book. 

First i created Common.ejs file which stores all the common JS functions.

GetNumberOfVisitors - provides the array size

WriteVisitorsData - Provides template for the Dropdown menu options and generates each options according to the index and Visitor name.

function GetNumberOfVisitors()
{
	return form["length"] * 1;
}

// Outputs the HTML of dropdown menu.
function WriteVisitorsData(index)
{
write('<option>' + form["VisitorsName" + index] + '</option>\n');
}

Next, part was the ESP file which generates the HTML code. I used a for loop and added the WriteVisitorsDate function to the for loop statement. 

<%
// CheckOut.esp
var cancelLink = form["cancelLink"];
var actionLabel = form["actionLabel"];
var ID = form["ID"];
include("../Common/Common.ejs"); // Include paths are relative to the ESP file.
//var VisitorsName = form["VisitorsName"];
var length = GetNumberOfVisitors();

%>

<html>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/3/w3.css">
<link rel="stylesheet" href="/lib/w3-theme-light-green.css">

<title>@@actionLabel Visitor's Log Book</title>

<body>

<center>
<h1>@@actionLabel</h1>

	<form action="/VisitorLogbook/Logs/CheckOut" method="post">
	<input name="ID" type="hidden" value="@@ID" />
		<fieldset>
		<div><label for="VisitorSelection">Select Visitor</label>
		<div><select name="VisitorSelection">

<%	// Generate a fieldset option for each visitor who did not checked out.
		for (var i=0; i < length; i++)
			{
%>			
				
			<% WriteVisitorsData(i); %>
			
<%		}
%>
		</select></div>
		</div>
		</fieldset>
		
	<p><input type="submit" value="@@actionLabel" /></p>
	</form>

	
<p><input type="button" value="Cancel" onclick="window.location.href='@@cancelLink'">
</center>
</body>
</html>

Next, the attached Checkout.vi provides the select name="VisitorSelection" this will help post the name to the vi and upon receiving the name the code will perform database operation and update the CheckOut time in the database for that particular visitor name. You can go by ID for more precise results, just in case if you have two people with same name (this is something i need to fix in next iteration).

 

Regards, 

max

 

Message 5 of 5
(3,235 Views)