Bay Six Software Forum Index Bay Six Software
Beyond the Basics
 
 FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[DEMO] RB Submit and Reset buttons

 
Post new topic   Reply to topic    Bay Six Software Forum Index -> Internet Programming
View previous topic :: View next topic  
Author Message
Brent
Site Admin


Joined: 01 Jul 2005
Posts: 728

PostPosted: Oct 2nd, 2007, 4:52pm    Post subject: [DEMO] RB Submit and Reset buttons Reply with quote

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
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Bay Six Software Forum Index -> Internet Programming All times are GMT
Page 1 of 1
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum



Lo-Fi Version
Powered by phpBB © 2001, 2005 phpBB Group