Главная страница Случайная страница КАТЕГОРИИ: АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника |
Dynamically Creating GUI Layouts
The " html.load.url" function introduced above can read an HTML file from the file system, or from an online web server: html.load.url " https://site.com/myform.html"If you need to create a GUI with a dynamically changing layout based upon user input or any other variable condition, use the " html.load.string" function. This allows you to concatenate an HTML string, and then display it as a GUI: input " Name: ", name$ frm$ = " < form action=\" form\" > Name: < br> " + ~ " < input type=\" text\" name=\" name\" value=\" " + ~ name$ + " \" > < br> < br> " + ~ " < input type=\" submit\" name=\" submit\" value=\" submit\" > " + ~ " < /form> " html.openhtml.load.string frm$do html.get.datalink data$until data$ < > " " data$ = mid$(data$, 5)print " Form data: " +data$The technique above provides a versatile way to create GUIs programmatically during runtime. It also provides a way to store code for GUI layouts directly within program code, so that no additional HTML files need to be distributed separately from the script. Notice the use of the " + ~" characters to concatenate the multiline string, and the use of the " \" character to include quotes within the quoted text. Another useful technique is to read an exising HTML file, and use the " replace$" function to dynamically alter the default layout. For example, the following code reads the myform.html document and changes the page color: grabfile frm$, " myform.html"! Replace the body tag with a body tag that contains a background color: frm$ = replace$(frm$, " < body> ", " < body bgcolor=\" #E6E6FA\" > ")html.openhtml.load.string frm$do html.get.datalink data$until data$ < > " " data$ = mid$(data$, 5)print " Form data: " + data$The following code does the exact same thing, but loads the HTML from a concatenated string, instead of from the external file: Using replace$ in this way, it's possible to change any predefined HTML in an existing GUI layout, add default data to forms, or make any other alterations, all at runtime, based on data entered by the user or any other dynamic factor(s). This is very powerful! Learning more HTML, CSS, and Javascript is helpful if you want to create impressively complex and/or responsive layouts, but the form elements you've seen so far provide all the essential components needed to collect data from users, in a way that's familiar and effective.
|