I have an assignment that I think I am almost complete but my head won’t give for much more, maybe I can be assited; my assignment called to create a html form that collects user data and validates user info; which I think I have correctly done. Now I have this instruction which I do not understand but think it is after the validation process “The merchandize items should include a link to the same or similar items on amazon.com or other retailor sites so that the potential buyers can have a better knowledge of the item and price of the new;” then I must have a thumbs-up image pop-up after the user clicks on the Submit button but I already have my validation form in the onclick.
Here’s my code:
<script language="JavaScript" type="text/javascript">
//Function to validate form
function validateForm() {
//Variables are declared
var s=document.forms["craigslistSalesForm"]["itemName"].value;
var t=document.forms["craigslistSalesForm"]["itemPrice"].value;
var u=document.forms["craigslistSalesForm"]["location"].value;
var v=document.forms["craigslistSalesForm"]["itemCondition"].value;
var w=document.forms["craigslistSalesForm"]["itemDescription"].value;
//If itemName is entered continue but if left blank show alert
if (s==null || s=="") {
alert("Please enter a title for your posting");
return false;
}
//If itemPrice is entered continue but if left blank show alert
if (t==null || t=="") {
alert("Please enter the price of your item");
return false;
}
//If location is entered continue but if left blank show alert
if (u==null || u=="") {
alert("Please enter your location");
return false;
}
//If itemCondition is entered continue but if left blank show alert
if (v==null || v=="Select a condition option") {
alert("Please choose the condition of your item from the list");
return false;
}
//Variables are declared
var x=document.forms["craigslistSalesForm"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
var y=document.forms["craigslistSalesForm"]["email2"].value;
//If email address doesn't contain symbol @ or . and a minimum 2 characters
//after dot then alert to correct email address
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) {
alert("Your email address must be in the format of name@domain.com");
return false;
}
//If second email address does not match first email then alert mis-match
if (y!=x) {
alert("Ooops! Your email does not match, please try again.");
return false;
}
//If itemDescription is entered continue but if left blank show alert
if (w==null || w=="") {
alert("You must describe your Item for Sale");
return false;
}
}
</script>
<html>
<head>
<title>Project Task #1 - AGV</title>
</head>
<body onload="document.getElementById('itemName').focus()" bgcolor="E1E1E1">
<form id="craigslistSalesForm">
<h2>PA Craigslist - Items for sale</h2>
<div>
<span>Posting Title:  </span><input tabindex="1" type="text" name="itemName"
id="itemName" size="35" maxlength="64" value>
    <span>Price:  </span>$<input type="text" name="itemPrice"
id="itemPrice" size="6" maxlength="9" value>
</div>
<br>
<div>
<span>Location:    </span><input type="text" name="location"
id="location" size="35" maxlength="64" value>
      <span>Item condition:  </span>
<select id="itemCondition" value>
<option>Select a condition option</option>
<option>New</option>
<option>Like new (in original packaging)</option>
<option>Like new (without original packaging
</option>
<option>Fairly used</option>
<option>Used</option>
<option>Rough condition</option>
<option>Working</option>
<option>Not working</option>
<option>I don't know</option>
</select>
</div>
<div>
                     
 
<input type="radio" value="Residential" name="typeOfLocation" CHECKED>Residential
    <input type="radio" value="Business" name="typeOfLocation">Business
</div>
<br>
<div>
<span>Your email:  </span><input type="text" name="email" id="email"
size="35" maxlength="64" value>
    <span><i>Retype your email:  </i></span><input type="text"
name="email2" id="email2" size="35" maxlength="64" value>
</div>
<br>
<div>
<span><b>Item Description:</b></span>
<br>
<textarea cols="80" name="itemDescription" id="itemDescription" style="width: 70%;
border: 3px solid black; font-family: Calibri; font-size: 24px;" rows="10"></textarea>
</div>
<button type="button" value="callTwoFunctions" onclick="validateForm()">
<b>Submit</b></button>
</form>
</body>
</html>
In your script you can have additional entry below of all validations you perform, which is accepted as a successful validation result:
… also you can have your other function that pops up something by appending its call after
validateForm()function in youronclickevent in button tag: