p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript How-To (http://p2p.wrox.com/forumdisplay.php?f=87)
-   -   alternate method of using MapQuest (http://p2p.wrox.com/showthread.php?t=37374)

tennisdad1 January 18th, 2006 08:20 PM

alternate method of using MapQuest
 
I am having a time trying to find a solution to my problem. Trying to create a form that allows user to enter a "From" location and selecting one of 4 different "To" locations. Mapquest basic code requires that the form fields id's start with either 1 or a 2, so I cannot create Javascript to populate the hidden fields based on a radio button (id values must start with alphabet). Another option would be to build the info into a string and then submit to MapQuest (needs to be a new window), but I have yet been able to uncover a method to accomplish this task without the form submitting the field names and ignoring my string.

Here is the link to MapQuest on how to link:
http://www.mapquest.com/features/main.adp?page=lf_dir

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

document.frmDir.action= txtFromLoc;

.....
<form onSubmit="return runMapQuest();" target="_blank" name="frmDir" >
<input type="hidden" name="go" value="1">
<div align="left">

Any thoughts?


vinod_yadav1919 January 23rd, 2006 06:45 AM

Hii tennisdad1!!

Can you tell

1>which options you are using
 Option #1
 Option # 2
 Option #3
2>if possible provide your javascript code and form(fields).




Cheers :)

vinod

tennisdad1 January 23rd, 2006 08:06 PM

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>



All times are GMT -4. The time now is 11:01 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.