ak1dnar 1,584
Recognized Expert Top Contributor
Hi, please help me on this.
Here i am having a simple form that consist with name and email fields and both are required fields.
i am going to validate this inputs using validate.php.
but since i am since i am using responseText object i couldn't display the error message for corresponding fields.
That means if name is blank error should appers in <span id="output_name ">
if email is blank error should appers in <span id="output_emai l">
and one more problem the loading message is not removing from the page.
here is my coding.
[HTML] <html>
<head>
<title>Sample Ajax</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body,td,th {
font-family: verdana;
font-size: 11px;
}
.style1 {color: #FF0000}
-->
</style></head>
<script language="javas cript">
window.onerror = function(msg, err_url, line) {alert('Unknown Error :) ' + line);}
function makeObject()
{
var x;
var browser = navigator.appNa me;
if(browser == "Microsoft Internet Explorer")
{
x = new ActiveXObject(" Microsoft.XMLHT TP");
}else
{
x = new XMLHttpRequest( );
}
return x;
}
var request = makeObject();
function post_method()
{
var name = sample_form.nam e.value;
var email = sample_form.ema il.value;
request.open('p ost', 'validate.php') ;
request.setRequ estHeader('Cont ent-Type', 'application/x-www-form-urlencoded');
request.onready statechange = output;
request.send('n ame='+name+'&em ail='+email);
}
function output()
{
if(request.read yState == 1)
{
document.getEle mentById('load_ msg').innerHTML = 'Loading...';
}
if(request.read yState == 4)
{
var errors = request.respons eText;
document.getEle mentById('outpu t_name').innerH TML = errors;
}
}
</script>
<body>
<DIV id="load_msg"> </DIV>
<form action="" method="post" name="sample_fo rm" id="sample_form ">
Name : <input type="text" name="name"><sp an id="output_name " class="style1"> * </span><BR>
Email : <input type="text" name="email"><s pan id="output_emai l" class="style1"> * </span><br>
<input type="button" name="Button" value="Submit" onClick="post_m ethod()">
</form>
</body>
</html>[/HTML]
validate.php
[PHP] <?php
$name = $_POST['name'];
$email = $_POST['email'];
if (stripslashes($ name) == "" )
{
echo 'Name Cannot be left Blank';
}
if (stripslashes($ email) == "" )
{
echo 'Email Cannot be left Blank';
}
?>
[/PHP]
2 3076 acoder 16,027
Recognized Expert Moderator MVP
Parse the response, e.g. add a delimiter such as "::", then use that to split the response.
As for your loading message, just set it to empty when the readystate is 4.
Why not just do the checking client-side? This is simple form validation. You don't need to use Ajax for that.
ak1dnar 1,584
Recognized Expert Top Contributor
Yes it is Acoder, this is a simple form.
I need to learn this then i can implement it for more complex form validation.
could you please give me a sample for this, any link or simple file.to understand the concepts.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Igor |
last post by:
Hi
I'm writing script using AJAX and PHP to upload files. I'm trying to
create progress bar to show how many bytes have been already uploaded to
server.
Can I get the total file size (using JS) before sending it to server or
immediately after start sending it?
And how to obtain amount o bytes that have been already transfered to
|
by: Ivan Marsh |
last post by:
Hey Folks,
I'm having a heck of a time wrapping mind around AJAX.
Anyone know of a simple, straight-forward example for pulling a simple
query from mysql with PHP using AJAX?
As I understand it I need a PHP script that pulls the query and dumps the
data into XML format, that is called by triggering a javascript event that
reads that file with XMLhttprequest.
|
by: pittendrigh |
last post by:
Are there any open source ajax/php html editors?
I want to incorporate as simple (very simple)
ajax based html editor into a webapp I'm making.
I spent an hour or so downloading code and
saw nothing that actually worked.
Don't need tables, just need to drag text around,
set fonts and colors, upload images, have
a simple form for making links.
|
by: moho |
last post by:
hi, I'm wondering how to get the fields from a list that I have. When sending it to the PHP page it doesn't seem to see it. I'm using this script for sending it to the PHP page. The getformvalues doesn't get the array in the field skills:
x.html
<form id="skillsform" name="skillsform" method="post" action="" >
<input id="skill" name="skill" type="text" onkeypress="autocompleteskills(this.value,event)"/><input name="add" value="add"...
|
by: ak1dnar |
last post by:
Hi i need to download some files (.pdf/.doc) from web root.
I am using a ajax script to send the file IDs and PHP will process it and it should generate the save as dialog box.
Currently without ajax when i process PHP file i can open the download box to save the file.
example:
http://localhost/website/download.php?fid=1005
but when i am sending the fid (using a onclick event of a Image i am sending the ID to JS func ) through Ajax...
| |
by: Haitashi |
last post by:
I have a multi-page form. The first page asks for an email and password. I want the user to enter their email address & password twice before they can click submit. The post action on this page is the second page of this form.
I wanted to include a script that would check if both emails and both passwords match on the fly; this is so they can receive a "live" response telling them that the emails don't match before they move on to the...
|
by: John Doe |
last post by:
Here's my issue: I have an instant messenger type feature for my site, its
basically an ajax IM feature. I run with a mysql backend on the site, i have
a div on my main page that runs a javascript timer to load the php page via
ajax every 15 seconds which checks the "pinguser" table to see if the user
has any chat requests, then echoes them to a div on the page. what i REALLY
want to do is have the ajax page see if there is a ping for the...
|
by: aua_usama |
last post by:
Dear all,
i am using ajax framework ver 1.0,
it is working fine with english when i switch the culture to arabic
the validation message is totally corrupted,
the proplem occure with all RTL culture.
any workaround ???
|
by: Amzul |
last post by:
hello all
i post the same Q in php forum i believe here its more suitable.
was wondering if anyone have a snipt of accordion in ajax/php before i have to dig in the .net section
does it have a diffrent name? all i can find is .net related
thanking you in advance
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |