Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 18th, 2006, 07:20 PM
Registered User
 
Join Date: Jan 2006
Location: Plainsboro, NJ, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?

Reply With Quote
  #2 (permalink)  
Old January 23rd, 2006, 05:45 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

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
Reply With Quote
  #3 (permalink)  
Old January 23rd, 2006, 07:06 PM
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
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter 10 - Alternate order walabok BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 March 19th, 2008 12:04 PM
Link to MapQuest snufse ASP.NET 2.0 Basics 2 January 9th, 2008 10:28 AM
Using Mapquest link ebdeasy Javascript How-To 0 June 2nd, 2006 06:15 PM
Alternate pictures / video Mantis Pro JSP 3 December 12th, 2004 07:09 AM
alternate ordering polecat XSLT 17 October 2nd, 2003 08:35 AM



All times are GMT -4. The time now is 10:22 AM.


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