Can help me do this javascript?

2007-07-29 6:36 pm
function clearUp() to reset all the fields when button reset is clicked function verify() ensure all the fields are filled up when button Submit is clicked when form submit successfully a message Order Submitted is displayed.

the form got 6 fields let say got date/period Required , Pick-Up Point , Destination Point , Name , Address , Phone

回答 (1)

2007-08-04 1:00 am
✔ 最佳答案
Is this what you want?

Please replace all the " with a double-quote. (") It's just an display error...

You'd also have to replace <form action="xxxx"> to point to wherever your form data needs to be sent to.

<html >
<head >
<script >
function clearUp(){

document.getElementById("date").value = "";
document.getElementById("pickup").value = "";
document.getElementById("destination").value = "";
document.getElementById("name").value = "";
document.getElementById("address").value = "";
document.getElementById("phone").value = "";

}


function verify(){

var message = "";

if (document.getElementById("date").value == "")
{
message += "Date/Period Required\n";
}
if(document.getElementById("pickup").value == "")
{
message += "Pick-Up Point\n";
}
if(document.getElementById("destination").value == "")
{
message += "Destination Point\n";
}
if(document.getElementById("name").value == "")
{
message += "Name\n";
}
if(document.getElementById("address").value == "")
{
message += "Address\n";
}
if(document.getElementById("phone").value == "")
{
message += "Phone\n";
}

if (message != "")
{
alert("The following required fields are missing:\n" + message);
return false;
}
alert("Order Submitted");
return true;
}

</script >
</head >
<body >

<form action="confirm.html" onsubmit="return verify();" />

Date/Period Required:
<br />
<input type="text" id="date" />
<br />
<br />

Pick-Up Point:
<br />
<input type="text" id="pickup" />
<br />
<br />

Destination Point:
<br />
<input type="text" id="destination" />
<br />
<br />

Name:
<br />
<input type="text" id="name" />
<br />
<br />

Address:
<br />
<input type="text" id="address" />
<br />
<br />

Phone:
<br />
<input type="text" id="phone" />
<br />
<br />

<input type="button" value="ClearUp" onClick="clearUp();" />
<input type="submit" value="Submit" />

</form >

</body >
</html >


收錄日期: 2021-04-23 17:09:29
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070729000051KK01212

檢視 Wayback Machine 備份