290 likes | 405 Views
Last time: Javascript (forms and functions). Last time: Javascript (forms and functions). <form action=" MAILTO:username@jhu.edu " method="post" enctype="text/plain">. Last time: Javascript (forms and functions). Let’s debug some code together:
E N D
Last time: Javascript (forms and functions) <form action="MAILTO:username@jhu.edu" method="post" enctype="text/plain">
Last time: Javascript (forms and functions) Let’s debug some code together: http://www.clsp.jhu.edu/~anni/cs103/test_before.html http://www.clsp.jhu.edu/~anni/cs103/test_after.html
Last time: Javascript (forms and functions) <body> <form> First name: <input type="text" name="firstname" /> Last name: <input type="text" name="lastname" /> <br> Gender: <select name="gender" id="g1" multiple="multiple" size="2"> <option value="male">male</option> <option value="female">female</option> </select> <input type="button" value="Submit" onclick="displaymsg(this.form)" /> </form> </body> <form action="MAILTO:username@jhu.edu" method="post" enctype="text/plain">
Last time: Javascript (forms and functions) <body> <form> First name: <input type="text" name="firstname" /> Last name: <input type="text" name="lastname" /> <br> Gender: <select name="gender" id="g1" multiple="multiple" size="2"> <option value="male">male</option> <option value="female">female</option> </select> <input type="button" value="Submit" onclick="displaymsg(this.form)" /> </form> </body> More control if you write the action yourself:
Last time: Javascript (forms and functions) <script type="text/javascript"> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg)) mailto(msg, form.lastname.value); } </script>
Last time: Javascript (forms and functions) <script type="text/javascript"> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg)) mailto(msg, form.lastname.value); } </script> Name of function
Last time: Javascript (forms and functions) <script type="text/javascript"> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg)) mailto(msg, form.lastname.value); } </script> arguments
Last time: Javascript (forms and functions) <script type="text/javascript"> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg)) mailto(msg, form.lastname.value); } </script> string = sum of other strings
Last time: Javascript (forms and functions) <script type="text/javascript"> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg)) mailto(msg, form.lastname.value); } </script> example: “Name: Ann Irvine Gender: Female”
Last time: Javascript (forms and functions) <script type="text/javascript"> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg)) mailto(msg, form.lastname.value); } </script> Pop up a window with the content of the message
Last time: Javascript (forms and functions) <script type="text/javascript"> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg)) mailto(msg, form.lastname.value); } </script> If the window is confirmed
Last time: Javascript (forms and functions) <script type="text/javascript"> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg))mailto(msg, form.lastname.value); } </script> call the function called “mailto”
Last time: Javascript (forms and functions) <script type="text/javascript"> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg))mailto(msg, form.lastname.value); } </script> Pass it two arguments
Last time: Javascript (forms and functions) <script type="text/javascript"> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg))mailto(msg, form.lastname.value); } </script> Receive two arguments
Last time: Javascript (forms and functions) <script type="text/javascript"> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg))mailto(msg, form.lastname.value); } </script> string = sum of other strings
Last time: Javascript (forms and functions) <script type="text/javascript"> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg))mailto(msg, form.lastname.value); } </script> string = sum of other strings
Last time: Javascript (forms and functions) <script type="text/javascript"> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg))mailto(msg, form.lastname.value); } </script> Dynamically load a page with this address
Last time: Javascript (forms and functions) <script type="text/javascript"> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg))mailto(msg, form.lastname.value); } </script> Details: semicolons
Last time: Javascript (forms and functions) <script type="text/javascript"> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg))mailto(msg, form.lastname.value); } </script> Details: Brackets
Last time: Javascript (forms and functions) <script type="text/javascript"> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg))mailto(msg, form.lastname.value); } </script> Details: javascript tags
Last time: Javascript (forms and functions) <script type="text/javascript"> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg))mailto(msg, form.lastname.value); } </script>
<body> <form> First name: <input type="text" name="firstname" /> Last name: <input type="text" name="lastname" /> <br> Gender: <select name="gender" id="g1" multiple="multiple" size="2"> <option value="male">male</option> <option value="female">female</option> </select> <input type="button" value="Submit" onclick="displaymsg(this.form)" /> </form> </body> <script type="text/javascript"> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg))mailto(msg, form.lastname.value); } </script>
<html> <head> <script type="text/javascript”> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg)) mailto(msg, form.lastname.value); } </script> </head> <body> <form> First name: <input type="text" name="firstname" /> Last name: <input type="text" name="lastname" /> <br> Gender: <select name="gender" id="g1" multiple="multiple" size="2"> <option value="male">male</option> <option value="female">female</option> </select> <input type="button" value="Submit" onclick="displaymsg(this.form)" /> </form> </body> </html> All of the javascript stuff
<html> <head> <script type="text/javascript”> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg)) mailto(msg, form.lastname.value); } </script> </head> <body> <form> First name: <input type="text" name="firstname" /> Last name: <input type="text" name="lastname" /> <br> Gender: <select name="gender" id="g1" multiple="multiple" size="2"> <option value="male">male</option> <option value="female">female</option> </select> <input type="button" value="Submit" onclick="displaymsg(this.form)" /> </form> </body> </html> All of the javascript stuff Form stuff
<html> <head> <script type="text/javascript”> function mailto(msg, lname) { subj = "600.103: Test Mail from " + lname; document.location.href = "mailto:Kenneth.Church@jhu.edu" + "?subject=" + subj + "&body=" + escape(msg); } function displaymsg(form) { msg = "Name: " + form.firstname.value + " " + form.lastname.value + "\n" + "Gender: " + form.gender.value; if(window.confirm(msg)) mailto(msg, form.lastname.value); } </script> </head> <body> <form> First name: <input type="text" name="firstname" /> Last name: <input type="text" name="lastname" /> <br> Gender: <select name="gender" id="g1" multiple="multiple" size="2"> <option value="male">male</option> <option value="female">female</option> </select> <input type="button" value="Submit" onclick="displaymsg(this.form)" /> </form> </body> </html> All of the javascript stuff Form stuff Use the javascript to email the form content
Last time: Javascript (forms and functions) Fix up some more code together (if time): http://www.clsp.jhu.edu/~anni/cs103/test2_before.html http://www.clsp.jhu.edu/~anni/cs103/test2_after.html
Next Up: Programming Phone Menus https://studio.tellme.com/
Homework • Make sure you have a working javascript-based survey on your website: • You should have functions like mailto and displaymsg (don’t rely on the html action tag that does this automatically and not so well) • Don’t worry about radio buttons and checkboxes, they’re harder • Include just textboxes and/or select lists • We’ll learn how to do this in a much easier way with Google Docs later • Go to https://studio.tellme.com/ and sign up for a free account. Play around if you have time, but at least have an account ready to program by next Tuesday