Студопедия

Главная страница Случайная страница

Разделы сайта

АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника






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:

frm$ = " < head> < title> Data Entry Form< /title> < /head> " + ~" < body> " + ~ " < form action=\" form\" > " + ~ " Name: < br> " + ~ " < input type=\" text\" name=\" name\" > < br> < br> " + ~ " Email: < br> " + ~ " < input type=\" text\" name=\" email\" > < br> < br> " + ~ " Message: < br> " + ~ " < textarea cols=25 name=\" message\" rows=5> Hi." + ~ " < /textarea> < br> < br> " + ~ " Preferred Day: < br> " + ~ " < select name=\" day\" > " + ~ " < option> Monday< option> Tuesday< option> Wednesday" + ~ " < option> Thursday< option> Friday< option> Saturday" + ~ " < option> Sunday< /option> " + ~ " < /select> < br> < br> " + ~ " Favorite Fruit(s): < br> " + ~ " < input type=\" checkbox\" name=\" f1\" " + ~ " value=\" fig\" checked> fig< br> " + ~ " < input type=\" checkbox\" name=\" f2\" " + ~ " value=\" apple\" > apple< br> " + ~ " < input type=\" checkbox\" name=\" f3\" " + ~ " value=\" orange\" > orange< br> " + ~ " < input type=\" checkbox\" name=\" f4\" " + ~ " value=\" banana\" > banana< br> < br> " + ~ " < input type=\" submit\" name=\" submit\" value=\" submit\" > " + ~ " < /form> " + ~" < /body> " 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$

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.






© 2023 :: MyLektsii.ru :: Мои Лекции
Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав.
Копирование текстов разрешено только с указанием индексируемой ссылки на источник.