Skip to content

Instantly share code, notes, and snippets.

View schickm's full-sized avatar

Matt Schick schickm

View GitHub Profile
@schickm
schickm / gist:11231866
Last active August 29, 2015 14:00
Getting a value from an input using jQuery
<input type="text" name="message">
<button type="button" class="show-message">Show The Message...</button>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script type="text/javascript">
// wait for someone to click on a button
$(".show-message").click(function() {
// get the value of the input, and show it in a dialog
alert( $("input[name='message'").val() );
@schickm
schickm / gist:11232750
Created April 23, 2014 21:17
Get the value and display it with some other text
<input type="text" name="message">
<button type="button" class="show-message">Show The Message...</button>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script type="text/javascript">
// wait for someone to click on a button
$(".show-message").click(function() {
// get the value of the input, and show it in a dialog
// preface it with another string of text
@schickm
schickm / gist:11233212
Last active August 29, 2015 14:00
Adding two values together
<p>
<input type="text" name="input-a">
<span>+</span>
<input type="text" name="input-b">
<p>
<button type="button" class="calculate">Add them up</button>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script type="text/javascript">
@schickm
schickm / gist:11233436
Created April 23, 2014 21:41
Concatenating a variable and some input text.
<input type="text" name="message">
<button type="button" class="show-message">Show The Message...</button>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script type="text/javascript">
// wait for someone to click on a button
$(".show-message").click(function() {
// get the value of the input, and show it in a dialog
// preface it with another string of text
@schickm
schickm / gist:11233636
Created April 23, 2014 21:49
Using multiple variables
<input type="text" name="message">
<button type="button" class="show-message">Show The Message...</button>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script type="text/javascript">
// wait for someone to click on a button
$(".show-message").click(function() {
// store value of the input a variable
var inputValue = $("input[name='message'").val();
@schickm
schickm / gist:11234243
Created April 23, 2014 22:11
Javascript: concatenating strings
var machine = "dish" + "washer";
alert(machine); // triggers a dialog box with the text "dishwasher"
@schickm
schickm / gist:11234265
Created April 23, 2014 22:12
Javascript: adding numbers
var total = 4 + 2;
alert(total); // shows "6"
@schickm
schickm / gist:11234345
Created April 23, 2014 22:14
Javascript: adding numbers and strings
var total = 4 + "2";
alert(total); // shows "42"
@schickm
schickm / gist:11234442
Created April 23, 2014 22:18
Javascript: parseInt
var total = 4 + parseInt("2");
alert(total); // shows "6" again!
@schickm
schickm / gist:11266970
Created April 24, 2014 19:40
Javascript: parseFloat
var total = 4 + parseFloat("3.5");
alert(total); // shows "7.5"!