Brent Site Admin
Joined: 01 Jul 2005 Posts: 800
|
Posted: Oct 2nd, 2007, 4:52pm Post subject: [DEMO] RB Submit and Reset buttons |
|
|
The following Run BASIC code shows how to create Submit and Reset buttons, which are not currently possible using native RB commands. It uses Javascript on the client side to replace LINKs (A's) with INPUT[type="submit"] buttons.
The main advantage of a true Submit button over a hyperlink, as used by RB, is that the form can be submitted to the server by simply pressing Enter. The Reset button, when clicked, will restore a form to its default state so that if the user makes a mistakes, he or she can easily restart without refreshing the page.
Note: This demo replaces all links on a page created by LINK with buttons.
Code: | ' Submit and Reset buttons demo
' By Brent D. Thorn, 9/2007
Cls
Print "Username: ";
TextBox #u, ""
Print
Print "Password: ";
PasswordBox #p, ""
Print
' the link acts as a placeholder and will be replaced by the submit button
Link #a, "Submit", [Login]
' create a reset button
HTML "<input type=""reset"" />"
' now the complicated part
HTML "
<script type=""text/javascript"">
<!--
var as = document.getElementsByTagName('A'); // get all A's
for ( var i = 0; i < as.length; i++ ) { // and iterate thru them all
if ( as[i].onclick ) { // looking for those with onclick
// event handlers
var el = document.createElement('INPUT'); // create an input
el.type = 'submit'; // and make it a submit button
el.onclick = as[i].onclick; // copy the event handler
el.value = as[i].firstChild.data; // get button's text from the link
as[i].parentNode.replaceChild(el, as[i]); // finally replace the link
}
}
//-->
</script>"
Wait
[Login]
u$ = #u Contents$()
p$ = #p Contents$()
Cls
Print "Username: "; u$
Print "Password: "; p$
Print "All done!"
End |
_________________ Brent |
|