Help Create a Button

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Help Create a Button

    Could anyone help me ?How can I create a web page with button that instructs server to turn on ou turn off something ?
    The examples with forms works but I don´t get to identify that a simple button was pressed and what button.
    Thanks a lot.

    Leonardo F. Farah
  • Hello Leonardo,

    Even a button needs to be part of a form as the <form> tag defines which action to take when the button is clicked.
    In this case the button would be a submit button, even if you name and label it with something else. Its purpose is to
    submit.

    If you want one on and another off button, you will either have to work with Javascript to let the button set a specific
    value that then can be submitted or you will have to use two form fields with one button each.

    Which button has been submitted can then be identified by the Web Server functions by the button name or value that
    has been specified. Everything else in your HTML code works like for any other standard Web Server.


    Hope this gives you a push into the right direction.

    Best regards,
    Oliver
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hello Oliver,

    Thank you for your help.
    I get the pressed button using the _callback_DefaultHandler of the cgi table ( WEBS_CGI ).

    Interestingly, the list is not only used for CGI coding "< ! - # Exec cgi = " anything " ->".

    Best regards,

    Leonardo F. Farah
  • Hello Leonardo,
    I get the pressed button using the _callback_DefaultHandler of the cgi table ( WEBS_CGI ).
    This happens because you do not have a CGI handler of the same name as your button installed.
    Let's have a look at the formGET.htm as an example:

    C Source Code

    1. <!-- -->
    2. <!-- Toggle LEDs -->
    3. <!-- -->
    4. <P><B>Set/clear LEDs:</B></P>
    5. <FORM ACTION="" METHOD="GET">
    6. <p>
    7. <input <!--#exec cgi="LED0"--> type="checkbox" name="LED0">LED0 &nbsp;
    8. <input <!--#exec cgi="LED1"--> type="checkbox" name="LED1">LED1 &nbsp;
    9. <input <!--#exec cgi="LED2"--> type="checkbox" name="LED2">LED2 &nbsp;
    10. <input <!--#exec cgi="LED3"--> type="checkbox" name="LED3">LED3 &nbsp;
    11. <input <!--#exec cgi="LED4"--> type="checkbox" name="LED4">LED4 &nbsp;
    12. <input <!--#exec cgi="LED5"--> type="checkbox" name="LED5">LED5 &nbsp;
    13. <input <!--#exec cgi="LED6"--> type="checkbox" name="LED6">LED6 &nbsp;
    14. <input <!--#exec cgi="LED7"--> type="checkbox" name="LED7">LED7 &nbsp;
    15. <INPUT TYPE="submit" VALUE="Change" name = "SetLEDs">
    16. </p>
    17. </FORM>
    Display All


    The button has been assigned the name "SetLEDs". This means if you want to do anything with this button you will have to install a handler for this name into the CGI table:

    C Source Code

    1. {"SetLEDs", _callback_SetLEDs },


    For multiple buttons you will need to install multiple handlers as well.
    Depending on the handler that is called you can now identify the pressed button.

    In case you want to use the same handler for multiple buttons this would make it necessary to use Javascript and will make it a little more complex.

    Best regards,
    Oliver
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.