View Single Post
  #3 (permalink)  
Old January 23rd, 2006, 08:06 PM
tennisdad1 tennisdad1 is offline
Registered User
 
Join Date: Jan 2006
Location: Plainsboro, NJ, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am trying to use the basic #3 option, but adding functionality to this option so that multiple stored "to" addresses can be made available to a user. The user could then just select a radio button which would enable the script to append the appropriate "To" address to the entered "From" address that the user has entered in the form.

The code that I am working on is as follows:

<script>
function frmVerify()
{
    if (isNaN(document.frmDir.1z.value))
    {
        document.frmDir.1z.focus();
        document.frmDir.1z.select();
        alert("Invalid Zip Code...please re-enter");
        return;
    }
}

function runMapQuest()
{
    var txtToLoc;
    var txtFromLoc = "http://www.mapquest.com/directions/main.adp?go=1+";
    switch (document.frmDir.radTo.value)
    { case 1:
        txtToLoc = "&2a=335+Princeton+Hightstown+Road&2c=Princeton+Ju nction&2s=NJ&2z=08550&2y=US&dir=Get+Directions";
        break;
      case 2:
        txtToLoc = "&2a=10+Schalks+Crossing+Road&2c=Plainsboro&2s=NJ& 2z=08536&2y=US&dir=Get+Directions";
        break;
      case 3:
        txtToLoc = "&2a=10+Southfield+Road&2c=Princeton+Junction&2s=N J&2z=08550&2y=US&dir=Get+Directions";
        break;
      default:
        txtToLoc = "&2a=90+Grovers+Mill+Road&2c=Plainsboro&2s=NJ&2z=0 8536&2y=US&dir=Get+Directions";
        break;
    }

    if (isNaN(document.frmDir.txtZip.value))
    {
        document.frmDir.txtZip.focus();
        document.frmDir.txtZip.select();
        alert("Invalid Zip Code...please re-enter");
        return;
    }

    var fromAddr = document.frmDir.txtAddr.value;
    var fromCity = document.frmDir.txtCity.value;

    var txtReplace = / /g;
    fromAddr = fromAddr.replace(txtReplace, "+");
    fromCity = fromCity.replace(txtReplace, "+");

    txtFromLoc = txtFromLoc+"&1a="+fromAddr+"&1c="+fromCity+"&1s="+ document.frmDir.txtState.value+"&1z="+document.frm Dir.txtZip.value+"&1y=US"+txtToLoc;

        document.frmDir.action= txtFromLoc;

    return true;

}
</script>

<body>

<form onSubmit="return runMapQuest();" target="_blank" name="frmDir" >
        <input type="hidden" name="go" value="1">
        <div align="left">
            <table border="0" cellpadding="0" cellspacing="0">
            <tr>
            <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
            <td colspan="2"><h4>FROM:</h4></td>
            </tr>
            <tr>
            <td width="133">Address or Intersection: </td>
            <td width="160"><input type="text" name="1a" size="22" maxlength="30" value=""></td>
            </tr>
            <tr>
            <td><div align="right">City: </div></td>
            <td><input type="text" name="1c" size="22" maxlength="30" value=""></td>
            </tr>
            <tr>
            <td><div align="right">State:</div></td>
            <td><select name="1s">
              <option value="CT">CT</option>
              <option value="MA">MA</option>
              <option value="MD">MD</option>
              <option value="NH">NH</option>
              <option value="NJ" selected>NJ</option>
              <option value="NY">NY</option>
              <option value="PA">PA</option>
              <option value="RI">RI</option>
              <option value="VA">VA</option>
              <option value="VT">VT</option>
              </select></td>
            </tr>
            <tr>
            <td> <div align="right">ZIP Code:</div></td>
            <td><input type="text" name="1z" size="8" maxlength="10" value="">
            <input name="1y" type="hidden" value="US"></td>
            </tr>
            <tr>
              <td valign="top"><div align="right">Site to Visit?: </div></td>
              <td><input name="2a" type="radio" value=1>The Dance Corner I<br>
                <input name="2a" type="radio" value=2>The Dance Corner II<br>
                <input name="2a" type="radio" value=3>WWPDC Performance<br>
                <input name="2a" type="radio" value=4>TDC Spring Recital
              </td>
              </tr>
            </table>
        </div>
        <h3>Mapquest directions </h3>
        <br>
        <div align="left">
            <img border="0" src="http://cdn.mapquest.com/mqstyleguide/ws_wt_sm" alt="MapQuest logo">
            <br>
            <input type="submit" name="dir" value="Get MapQuest Directions" onclick="frmVerify();">
            <br>
            <input type="hidden" name="CID" value="lfddwid">
        </div>
        </form>

Reply With Quote