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 7900323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:56:31+00:00 2026-06-03T08:56:31+00:00

Have searched for the answer but no joy, so here goes… I’m working on

  • 0

Have searched for the answer but no joy, so here goes…

I’m working on a mobile hybrid app. I want the user to fill in their id number, which is then submitted to a javascript function for basic validation, then kicks in a jQuery.getJSON request to my serverside PHP which returns the data and then my jQuery will repopulate the form div with the data.

Currently it doesn’t really work at all in Firefox, and only works correctly in Safari after I press the submit button for a second time. It returns the correct data, so the link is ok.

My problem is: Why does the div not get repopulated after the first click?

HTML:

<div id="login540div">
<form id="login540form" onSubmit="login540()">
Enter Student ID number<input type="text" name="login540id" id="login540id"/>
<input type="submit" value="Submit" />
</form>
</div>

Javascript:

function login540(){
// validates the data entered is an integer. 
var loginNo = document.getElementById("login540id").value;
//if(!isNaN(loginNo))
 if((parseFloat(loginNo) == parseInt(loginNo)) && !isNaN(loginNo))
{

 //jSonCaller(loginNo); 
 $.getJSON('http://localhost:8888/c05673160/login540.php?q='+loginNo, function(data){

//alert(data);
$('#login540div').html("<p>First Name ="+
data.firstName+
"</p> Last Name ="+data.lastName+" </p>Module No.1 ="+
data.moduleNo1+"</p> Module No.2 ="+
data.moduleNo2+"<p> Course ID="+
data.courseID+"</p>");
    })

}
  else 
    {
    // alert(loginNo);  CHECKED
    alert("Please make sure to insert only a whole number");
        } 

Then the PHP goes like this…

    <?php
include ("config.php");
/*
require_once('FirePHPCore/FirePHP.class.php');
ob_start();
$firephp = FirePHP::getInstance(true);

$var = array('i'=>10, 'j'=>20);

$firephp->log($var, 'Iterators');
*/

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'root';
$dbname = 'collegeData';

$q=$_GET["q"];

$table = "studentTable";
$conn = mysql_connect($dbhost, $dbuser, $dbpass);

if (!$conn)     
    die('Could not connect: ' . mysql_error());
if (!mysql_select_db($dbname))    
    die("Can't select database");   

$result = mysql_query("SELECT * FROM {$table} WHERE studentID = '".$q."'");
if (!$result)  
    die("Query to show fields from table failed!" . mysql_error());

$json = array();
while($row = mysql_fetch_array ($result))     
{
    $json = array(
        'firstName' => $row['firstName'],
        'lastName' => $row['lastName'],
        'moduleNo1' => $row['moduleNo1'],
        'moduleNo2' => $row['moduleNo2'],
        'courseID' => $row['courseID']
    );
}

$jsonstring = json_encode($json);
echo $jsonstring;

mysql_close($conn);
?>

I can’t figure out what’s wrong, and I’ve been messing around with various things for the last few days trying to fix it, but no joy, so I’d really appreciate any help you can give.

  • 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-03T08:56:32+00:00Added an answer on June 3, 2026 at 8:56 am

    @Robbie had a good point that you don’t appear to be stopping the default behavior of the form submission. To do this you need to change a couple things:

    1. onSubmit="login540()" needs to change to onSubmit="return login540()" otherwise whatever you return from the login540() function will be ignored.
    2. At the end of the login540() function you need to return false; to stop the form from submitting normally. You can also pass in the event object as the first argument and use event.preventDefault() instead: function login540(event){event.preventDefault();...}.

    To do yourself a favor however, you can use jQuery to bind the submit event handler to the form rather than using inline JS (tisk, tisk, 🙂 )

    $('#login540form').on('submit', login540);
    

    This way you can keep all of your JS in one place rather than spread-out all over your HTML.

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

Sidebar

Related Questions

I have searched Google and looked here but I haven't quite found the answer
I have searched for an answer but couldn't find it anywhere. My question is
I have searched but have not found my answer. Disclaimer: I am brand new
I have searched a bit on google, but didn't really found an answer to
I have searched for an answer but am not finding it. I have 2
I have searched already but unable to find an answer that works. I simply
I have searched quite thoroughly on this but can't seem to find an answer.
I have searched the site for this simple problem but cant find an answer.
I have searched internet and stackoverflow thoroughly, but I haven't found answer to my
I have searched stackoverflow to find an answer but i can not find one.

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.