cancel
Showing results for 
Search instead for 
Did you mean: 

Web Browser Application.

IAgui
Associate II

 Lets say I have this as my HTML page

<form method="get" action="/leds.cgi">

<input value="1" name="led" type="checkbox">LED1<br>

<input value="2" name="led" type="checkbox">LED2<br>

<br>

<p>text for tag1: <!--#tag1--></p>

<p>text for tag2: <!--#tag2--></p>

<input value="Send" type="submit"> </form>

and my CGI handler looks like this:

/**** CGI handler for controlling the LEDs ****/

// the function pointer for a CGI script handler is defined in httpd.h as tCGIHandler

const char * LedCGIhandler(int iIndex, int iNumParams, char *pcParam[], char *pcValue[])

{

uint32_t i=0;

// index of the CGI within the theCGItable array passed to http_set_cgi_handlers

// Given how this example is structured, this may be a redundant check.

// Here there is only one handler iIndex == 0

if (iIndex == 0)

{

HAL_GPIO_WritePin(LD3_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);

HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);

// Check the cgi parameters, e.g., GET /leds.cgi?led=1&led=2

for (i=0; i<iNumParams; i++)

{

//if pcParmeter contains "led", then one of the LED check boxes has been set on

if (strcmp(pcParam[i], "led") == 0)

{

//see if checkbox for LED 1 has been set

if(strcmp(pcValue[i], "1") == 0)

{

// switch led 1 ON if 1

HAL_GPIO_WritePin(LD3_GPIO_Port, LD2_Pin, GPIO_PIN_SET);

pcValue[i] = "1";

}

//see if checkbox for LED 2 has been set

else if(strcmp(pcValue[i], "2") == 0)

{

// switch led 2 ON if 2

HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_SET);

}

} //if

} //for

} //if

//uniform resource identifier to send after CGI call, i.e., path and filename of theresponse

pcValue[1] = "1";

return "/index.shtml";

}

When the user selects the checkbox for an led I want to have it remain selected to indicate that it is on. That's where I am having the issues. Any insight would be greatly appreciated.

2 REPLIES 2
Piranha
Chief II

You have to reload page with attribute checked for particular <input> elements.

https://www.w3schools.com/tags/att_input_checked.asp

IAgui
Associate II

Sorry for the late response. Had to put out a fire before I got back to this. I will be giving this a try.