0

Hi,

In part of my form, I have 3 inputs (one textarea and two text inputs), I am validating their value format using AJAX (each input triggers error message on its label in case format is wrong). Also I have one button, "NOT submit button" (type = button).

Now, when clicking on the button it must enter the value of those three inputs in my database in case they are true then all inputs values must be cleared. In case AJAX validation is wrong and in case the user clicked on that button, the value of fields must kept as it is.

Actually I can not use submit button because I have it for the whole form and what I am taking about is a part of the form and it's not possible to make nested forms as I know it violates html rules. It's easy to make it if I am taking about submitting button as I can view session values on fields after submission in case ajax returns error.

I can clear inputs from Javascript, but it will be cleared on both cases if AJAX validation true or wrong.

in Summary:
---------------
Each input field has AJAX Error message that will be triggered when the input format is wrong.

I need:
If AJAX validation is giving wrong, and if the user clicks on that button, all fields must kept same.

If AJAX validation is giving "no error" and when the user clicks on that button, all fields must be cleared and values will be transferred to database.

The question how to keep values in case ajax return errors and how to clear them in case ajax returns "no errors" :)

Your advice will be highly appreciated.

Thanks in advance.

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Moderns
0

Consider that on click of a button you are calling a function that does the AJAX calls and other stuff.
You can add more parameters to that function which can be ids of the elements to be validated and in onreadystatechange function process using this ids with
e.g.
document.getElementById(sTestId).value="";
or
You can pass the document.form object itself and than manipulate the items.

Actually it all depends on how the AJAX calls are made and where the results are processed.
It would really help if you could post code snippets

0

Consider that on click of a button you are calling a function that does the AJAX calls and other stuff.
You can add more parameters to that function which can be ids of the elements to be validated and in onreadystatechange function process using this ids with
e.g.
document.getElementById(sTestId).value="";
or
You can pass the document.form object itself and than manipulate the items.

Actually it all depends on how the AJAX calls are made and where the results are processed.
It would really help if you could post code snippets

Thanks parry_kulk for your support always :)

I will try both solutions and will let you know, I will travel today outside my country for 5 days and come back.

0

Hi,

I just came back from my trip.

Actually, my system should check in the database, if the username entered is correct, then after clicking on that button it must clear the field, otherwise, it must keep it.

I think I have to use the XML call using AJAX as the normal text response is not working because I have to view other outputs on every click, if not (will not view other outputs) I can make IF in javascript (onreadystate) function like:

if (response) // if entered value matches the database value
document.getElementById(username_field).value ="";
else
document.getElementById(username_field).value = entered_username

I think XML call can solve the probelm as I get returned value from the PHP script which indicates that the username exists in database or not.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.