2

I am currently learning how to make a simple web form. Here is what I want to achieve:

To create a simple html web form that pass a number to php and then it show back the number in another text field (without refreshing the page).

I searched on the net and many people suggest to use AJAX or javascript. I am wondering is it possible to do the said function only using a notepad++ and html and php code?

Thanks in advance Sunny

  • 2
    You need to understand the difference between server-side and client-side scripting. HTML and JavaScript/jQuery are client side, and PHP is server-side. This means that PHP is executed before any HTML or JavaScript. So if you don't want to refresh the page, and still update/set/do something in PHP after sending it from the server, you need AJAX or something similar. Notepad++ is just an editor, it doesn't *do* anything. – Qirel Jan 03 '16 at 13:46

3 Answers3

1

No, once the page has been rendered there is no way to make the PHP code re-run. You need javascript (better yet, jQuery - a js library that makes js MUCH easier and WAY faster to type) to catch the user's activity that will trigger the interaction.

HOWEVER, AJAX is actually way easier than you might think.

Here are some basic posts for getting a feel for AJAX:

A simple example

More complicated example

Populate dropdown 2 based on selection in dropdown 1

Want to learn more about it?

theNewBoston ajax tutorial (free)

Community
  • 1
  • 1
cssyphus
  • 37,875
  • 18
  • 96
  • 111
0

You will need JavaScript to do this interaction without refreshing the page.

eckymad
  • 1,032
  • 8
  • 6
0

without refreshing the page

&

without using javascript

It's not possible. You should use AJAX in cases like that.

coolguy
  • 3,011
  • 2
  • 18
  • 35