Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5841429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:53:22+00:00 2026-05-22T11:53:22+00:00

I have an html form with two input fields, in first one user puts

  • 0

I have an html form with two input fields, in first one user puts name of first town, and in other second town, after form is submitted users gets directions how to go from first town to second town.

I want to enable user to click button “Change directions” and to automatically change first town name into second and second town name into first and vise versa. ( A to B, B to A)

I guess i’m supposed to use javascript, but I’m new at it and can’t get a clue anywhere.

Can anyone help me please?

input type="text" size="25" id="fromAddress" name="from"
 value=""/>
  <input name="submit1" type="submit" value="Change directions" />
<input type="text" size="25" id="toAddress" name="to"
 value="" />
<input name="submit" type="submit" value="OK" />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:53:22+00:00Added an answer on May 22, 2026 at 11:53 am

    Below is the sample code of what you want to achieve enjoy 🙂

            function swap1() {
                var data1 = document.getElementById("fromAddress").value;
                var data2 = document.getElementById("toAddress").value;
                document.getElementById("fromAddress").value = data2;
                document.getElementById("toAddress").value = data1;
                document.getElementById("swap_button").onclcik = function () {swap2()};
            }
    
            function swap2() {
                var data1 = document.getElementById("toAddress").value;
                var data2 = document.getElementById("fromAddress").value;
                document.getElementById("toAddress").value = data2;
                document.getElementById("toAddress").value = data1;
                document.getElementById("swap_button").onclcik = function () {swap2()};
            }
    
    
        <input type="text" size="25" id="fromAddress" name="from" value=""/>
        <input id="swap_button" type="button" value="Change directions" onclick="swap1()" />
        <input type="text" size="25" id="toAddress" name="to" value="" />
        <input name="submit" type="submit" value="OK" />
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.