Jump to content

Recommended Posts

The form wants the user to input a display name.

 

The goal is to check via the jquery $.POST function to send back to this page to check to see if the display name is available.

 

 

This is the table on the registration page.

<table border = '1'>
<form id = 'register' action = '#' method = 'post'>
<tr><td width = '150'>Display: </td><td width = '200'><input id = 'display' type = 'text' name = 'display' maxlength = '35'></td><td id = 'displaycheck' align = 'center' width = '80'>
<?php
if(isset($_POST['display']))
{
$display = htmlspecialchars($_POST['display']);
$display = mysql_real_escape_string($display);

$result = mysql_query("SELECT display FROM user WHERE display = '$display' ");
$count = mysql_num_rows($result);
if($count == 1)
{
echo "<font color = 'red'>Taken.</font>";
}
else
{
echo "<font color = 'green'>Accepted.</font>";
}

}
?>
</td></tr></table>

 

 

 

This is the Jquery Code:

 

$(document).ready(
function ()
{
//Display
 $('#display').focusin( function() {
  $('#directions').html('For your display name, you can have up to 35 characters which includes letters, numbers, underscores, periods, and spaces.');
 });

 $('#display').keyup( function() {

  var display = $(this).val();
  $.post('/registration.php', {display: display}, function(data) {
  $('#displaycheck').html(data);
  });
 });
);
});

 

 

What's happening is the ENTIRE table is reprinted in the table CELL 'displaycheck'. I have NO idea why the entire table is being resent. Can someone pelase help?? I haven't got a clue on how to fix this.

Edited by notsophpfreakish
Link to comment
https://forums.phpfreaks.com/topic/271826-jquery-post-result-messes-up-table/
Share on other sites

$.post submits data, so by doing it to registration.php and returning html, all html page will be displayed where you set it, in your case you set it to #displaycheck

 

 

// submits to registration.php
$.post('/registration.php', {display: display}, function(data) {

// returns all html on registration.php to the div with id of displaycheck
$('#displaycheck').html(data);

I would make a separate php file. Submit the data to it and check on there, echo out anything you need because that is considered html.

 

 

otherpage.php

<?php
echo "jquery ftw";
?>

 

jquery:

// submit to other page
$.post('/otherpage.php', {display: display}, function(data) {

// will display jquery ftw in the displaycheck div
$('#displaycheck').html(data);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.