What city do you live in?

What state do you live in?

There are a few different ways to go about this. Here's one method.

<html>
  <head>


  <SCRIPT type="text/javascript">
  function doit()
  {


    var greeting="I like "
    alert(greeting + document.aform.city.value 
	 + " " + document.aform.state.value)
    alert
      ("There are " + document.aform.city.value.length 
	 + " letters in your city name.")
  }
  </script>
  </head>
  <body >

  <form name="aform">
    What city do you live in? 
	<INPUT TYPE="text" NAME="city">
    What state do you live in? 
	<INPUT TYPE="text" NAME="state">
    <input type="button" 
	  value="Click Here" onClick="doit()">
  </form>
  </body>
  </html>

Notice I changed out the named of the input boxes with the names "city" and "state". I then erased the first alert box from Primer 19's example and it pretty much ran from there.

Close this window to return to JavaScript Primer