0

I've designed an HTML form to find the GPA , I want to ask the user to enter the mark, and pushing on "submit" button which sending marks to php Class in other page in the same project, the class should process the mark and find GPA , and then send GPA to the same HTML form and print it in a text box ;

i used submit button to go to PHP class.

this is the form's tag which i used

<form method="post" action="GPA.PHP">

After processing the data in php class, i want to send the result to html and put them into a text, this text :

<input type="text" style="text-align:center;" value="0.0" name="GPA" /> 

how can i do this ??

2
  • Have you tried anything yet? Any attempts or research? Like, I don't know, something like what's offered on PHP.net? Commented Jul 11, 2013 at 21:50
  • maybe you should learn jquery and/or php. Who is GPA? Commented Jul 11, 2013 at 21:53

2 Answers 2

1

First, give an id to the input, e.g. :

<input type="text" style="text-align:center;" value="0.0" name="GPA" id="result" /> 

Second, make sure that the form isn't submitted with its regular behaviour, by returning false on submit:

<form method="post" action="GPA.PHP" onSubmit="return false;">

And third, you may call the following javascript code when the submit button is clicked or whe the form is submitted:

$.ajax({
  type: "POST",
  url: "gpa.php",
  data: { mark: "50" }
}).done(function( msg ) {
  $('#result').val(msg);
});

I hope it works :)

Sign up to request clarification or add additional context in comments.

1 Comment

where should i put the third code ?? i didn't use java script in my code.
0

I think I understand what you're saying. What you want to do is use ajax: http://api.jquery.com/jQuery.ajax/

$.ajax({
  type: "POST",
  url: "gpa.php",
  data: { mark: "50" }
}).done(function( msg ) {
  $('div.gpa').html(msg);
});

So Post the students score (lets say they got 50 for this example) to gpa.php. On the gpa.php you would have you code to calculate the gpa and the send it back as msg. This would then output the gpa to the div id of gpa.

2 Comments

where should i put the third code ?? i didn't use java script in my code.
The third code? You need to use javascript if you want the data to appear in your table without reloading the page etc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.