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

  • SEARCH
  • Home
  • 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 7746517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:17:54+00:00 2026-06-01T10:17:54+00:00

I currently have some code which when you press the submit button, a marker

  • 0

I currently have some code which when you press the submit button, a marker should be placed on a map according to the value that is in a drop down list box. I have made it so that the value in the drop down box will go into the URL via a GET form method for the PHP code and will also pass the value via parameter to the javascript function.

The problem I am having is that I have to press the submit button twice so that the marker will appear on the map. This is less then ideal and I am looking for some help to try fix this problem. Thanks.

This is the javascript function code:

function placeMarker(address) 
        {       
            // ... Set up map code here

            var map = new google.maps.Map(document.getElementById("universityMap"), myOptions);

            <?php
                $uniname = $_GET['uninames'];       

                //Get the Uni code according to the uni name
                $queryUniID = $mysqli->prepare("SELECT IdCode FROM universityid WHERE UniName = ?");
                $queryUniID->bind_param('s', $uniname);
                $queryUniID->execute();
                $queryUniID->bind_result($unicode);
                $queryUniID->fetch();
                $queryUniID->close();

                //Load the question data into relevant variables
                $queryQuestions = $mysqli->prepare("SELECT QuestionNo, Answered1, Answered2, Answered3, Answered4, Answered5 FROM nssdata WHERE UniID = ?");
            ?>

            address = address + ", UK";
            geocoder.geocode({'address': address}, function(results, status) 
            {
                if (status == google.maps.GeocoderStatus.OK) 
                {
                    marker = new google.maps.Marker(
                    {
                        map: map,
                        position: results[0].geometry.location,
                        title: address, 
                        draggable: false
                    });
                }
                else 
                {
                    alert(status);
                }
            });
        }

This is my html form:

        <form action="#" onsubmit="placeMarker(this.uninames.value)" method="get">
  • 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-06-01T10:17:56+00:00Added an answer on June 1, 2026 at 10:17 am

    This should actually work, provided that your values are all within proper ranges. In testing a reduced version of this, I can type an address, click submit and markers show up right where they should be.

    I have a few theories as to why you are clicking twice before seeing a result.

    (1) Lookup latency: make sure to track geocoder states and give it ample time to perform.

    (2) Glitch: In some map renderers, you sometimes need to cycle maps for a marker. For example, this set of successive calls: marker.setMap( null ); marker.setMap( map ); will hide/show a marker and sometimes unglitch the display.

    (3) Submit interruption: If the interface is more complex than you have stated and is possibly interfering, your form submit (#) probably needs to be prevented from submitting. In other words, you must stop the browser from going to the # address after clicking submit so you can let JavaScript/ajax do its work.

    Here’s a reduced version of the form; note the return(false) part – it prevents browser address from changing to #.

    <form action="#" onsubmit="placeMarker('adr');return( false );" method="get">
        <input type="text" id="id_address" />
        <input type="submit" />
    </form>
    

    Note that I simplified this address to text; in my actual test I sent data this way:

    placeMarker(document.getElementById('id_address').value);

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

Sidebar

Related Questions

I have some code that currently checks for minimum and maximum lentgh. I want
I currently have some objective C code which I use to identify the difference
I have inherited some code which involves a scheduled task that writes data (obtained
I currently have some code which returns a sites header content back: #!/usr/bin/perl use
I currently have some code that cycles through a text file looking for a
I currently have some code which grabs some JSON from a site. This is
We currently have some php code that allows an end user to update records
I currently have some code which needs to perform multiple updates per user for
I currently have some code that sets up notifications of connected USB HID devices
I've been trying to implement unit testing and currently have some code that does

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.