html form 提交两个do,HTML form do some “action” when hit submit button

本文介绍了如何在Windows系统上安装和配置PHP及web服务器,从而开始PHP编程。通过创建两个页面,演示了如何使用PHP处理HTML表单数据。示例中展示了如何显示用户输入的姓名和年龄,并利用JavaScript从表单中获取并显示数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Ok, I'll take a stab at this. If you want to work with PHP, you will need to install and configure both PHP and a webserver on your machine. This article might get you started: PHP Manual: Installation on Windows systems

Once you have your environment setup, you can start working with webforms. Directly From the article: Processing form data with PHP:

For this example you will need to create two pages. On the first page

we will create a simple HTML form to collect some data. Here is an

example:

Test Page

Data Collection

Name:
Age:

This page will

send the Name and Age data to the page process.php. Now lets create process.php to use

the data from the HTML form we made:

print "Your name is ". $Name;

print "
";

print "You are ". $Age . " years old";

print "
"; $old = 25 + $Age;

print "In 25 years you will be " . $old . " years old";

?>

As you

may be aware, if you leave out the method="post" part of the form, the

URL with show the data. For example if your name is Bill Jones and you

are 35 years old, our process.php page will display as

http://yoursite.com/process.php?Name=Bill+Jones&Age=35 If you want,

you can manually change the URL in this way and the output will change

accordingly.

Additional JavaScript Example

This single file example takes the html from your question and ties the onSubmit event of the form to a JavaScript function that pulls the values of the 2 textboxes and displays them in an alert box.

Note: document.getElementById("fname").value gets the object with the ID tag that equals fname and then pulls it's value - which in this case is the text in the First Name textbox.

function ExampleJS(){

var jFirst = document.getElementById("fname").value;

var jLast = document.getElementById("lname").value;

alert("Your name is: " + jFirst + " " + jLast);

}

First name:

Last name:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值