Just trying to teach myself a bit of HTML+Javascript but have run into an error trying to use an external javascript to validate a HTML.
Currently the HTML looks something like this.
<!DOCTYPE html>
<html lang="en">
<head>
<Title>Book Event</Title>
<meta charset="utf-8">
</head>
<body>
<h1>Book Event</h1>
<p></p>
<p> Click on the numbers next to the event to autofill the form!</p>
<script src="validation.js"></script>
<form name="myForm" action="/action_page.php" onsubmit="return validateForm()" method="post">
<label for="datemin">Date of Event:</label>
<input type="date" id="datemin" name="datemin" min="2020-02-01"><br><br>
<label for="ename">Event name:</label><br>
<input type="text" id="ename" name="ename"><br>
<label for="Time">Time of Event:</label><br>
<input type="text" id="Time" name="Time" value=" "><br><br>
<fieldset>
<legend>Selecting Location</legend>
<p>
<label>Select Location</label>
<select id = "Location" name = "Location">
<option value = "L1">Perth</option>
<option value = "L2">Duidgee Park, Toodyay</option>
<option value = "L3">Canning Highway</option>
</select>
</p>
</fieldset>
<p> </p>
<fieldset>
<legend>Selecting Price</legend>
<p>
<label>Select Price</label>
<select id = "Price" name = "Price">
<option value = "P1">$20</option>
<option value = "P2">$30</option>
<option value = "P3">$40</option>
<option value = "P4">$50</option>
<option value = "P5">$80</option>
</select>
</p>
</fieldset>
<label for="quantity">Quantity:</label>
<input type="number" id="quantity" name="quantity" min="1" max="99"><br><br>
<input type="submit" value="Submit">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a page called "/action_page.php".</p>
<p></p>
<table>
<thead>
<tr>
<th></th>
<th> Event </th>
<th> Date </th>
<th> Time </th>
<th> Location </th>
<th> Price </th>
</tr>
</thead>
<tbody>
<tr>
<td> <a href="#" onClick="autoFill1(); return true;" >1</a> </td>
<td> Fatboy Slim </td>
<td> FEB 2 </td>
<td> Sun, 7:00 pm - 10:00 pm </td>
<td> Perth </td>
<td> $40 </td>
</tr>
<tr>
<td> <a href="#" onClick="autoFill2(); return true;" >2</a> </td>
<td> Bastille </td>
<td> FEB 4 </td>
<td> Tue, 7:00 pm - 10:00 pm </td>
<td> Perth </td>
<td> $30 </td>
</tr>
<tr>
<td> <a href="#" onClick="autoFill3(); return true;" >3</a> </td>
<td> A-HA </td>
<td> FEB 19 </td>
<td> Wed, 7:00 pm - 10:00 pm </td>
<td> Perth </td>
<td> $50 </td>
</tr>
<tr>
<td> <a href="#" onClick="autoFill4(); return true;" >4</a> </td>
<td> Michael Buble </td>
<td> FEB 21 </td>
<td> Fri, 7:00 pm - 10:00 pm </td>
<td> Perth </td>
<td> $80 </td>
</tr>
<tr>
<td> <a href="#" onClick="autoFill5(); return true;" >5</a> </td>
<td> SAFIA </td>
<td> FEB 29 </td>
<td> Sat, 12:00 pm </td>
<td> Perth </td>
<td> $30 </td>
</tr>
<tr>
<td> <a href="#" onClick="autoFill6(); return true;" >6</a> </td>
<td> Perth Festival 2020 - Highway to Hell </td>
<td> MAR 1 </td>
<td> Sunday </td>
<td> Canning Hwy </td>
<td> $20 </td>
</tr>
<tr>
<td> <a href="#" onClick="autoFill7(); return true;" >7</a> </td>
<td> Toodyay Music Fest </td>
<td> MAR 28 </td>
<td> Sat, 10:00 am - 9:00 pm </td>
<td> Duidgee Park, Toodyay </td>
<td> $20 </td>
</tr>
<tr>
<td> <a href="#" onClick="autoFill8(); return true;" >8</a> </td>
<td> City And Colour </td>
<td> APR 17 </td>
<td> Fri, 7:00 pm - 10:00 pm </td>
<td> Perth </td>
<td> $50 </td>
</tr>
<tr>
<td> <a href="#" onClick="autoFill9(); return true;" >9</a> </td>
<td> Backstreet Boys 2020 </td>
<td> MAY 30 </td>
<td> Sat, 8:00 pm - 11:00 pm </td>
<td> Perth </td>
<td> $80 </td>
</tr>
</tbody>
</table>
<p> </p>
<script>
function autoFill1()
{
document.getElementById('Location').value = "L1";
document.getElementById('ename').value = "Fatboy Slim";
document.getElementById('datemin').value = "2020-02-02";
document.getElementById('Time').value = "7:00 pm - 10:00pm"
document.getElementById('Price').value = "P3"
}
function autoFill2()
{
document.getElementById('Location').value = "L1";
document.getElementById('ename').value = "Bastille";
document.getElementById('datemin').value = "2020-02-04";
document.getElementById('Time').value = "7:00 pm - 10:00pm"
document.getElementById('Price').value = "P2"
}
function autoFill3()
{
document.getElementById('Location').value = "L1";
document.getElementById('ename').value = "A-HA";
document.getElementById('datemin').value = "2020-02-19";
document.getElementById('Time').value = "7:00 pm - 10:00pm"
document.getElementById('Price').value = "P4"
}
function autoFill4()
{
document.getElementById('Location').value = "L1";
document.getElementById('ename').value = "Michael Buble";
document.getElementById('datemin').value = "2020-02-21";
document.getElementById('Time').value = "7:00 pm - 10:00pm"
document.getElementById('Price').value = "P5"
}
function autoFill5()
{
document.getElementById('Location').value = "L1";
document.getElementById('ename').value = "SAFIA";
document.getElementById('datemin').value = "2020-02-29";
document.getElementById('Time').value = "12:00PM"
document.getElementById('Price').value = "P2"
}
function autoFill6()
{
document.getElementById('Location').value = "L3";
document.getElementById('ename').value = "Perth Festival 2020 - Highway to Hell";
document.getElementById('datemin').value = "2020-03-01";
document.getElementById('Time').value = "Null"
document.getElementById('Price').value = "P1"
}
function autoFill7()
{
document.getElementById('Location').value = "L2";
document.getElementById('ename').value = "Toodyay Music Fest";
document.getElementById('datemin').value = "2020-03-28";
document.getElementById('Time').value = "10:00am - 09:00pm"
document.getElementById('Price').value = "P1"
}
function autoFill8()
{
document.getElementById('Location').value = "L1";
document.getElementById('ename').value = "City and Colour";
document.getElementById('datemin').value = "2020-04-17";
document.getElementById('Time').value = "07:00pm - 10:00pm"
document.getElementById('Price').value = "P4"
}
function autoFill9()
{
document.getElementById('Location').value = "L1";
document.getElementById('ename').value = "Backstreet Boys 2020";
document.getElementById('datemin').value = "2020-05-20";
document.getElementById('Time').value = "08:00pm - 11:00pm"
document.getElementById('Price').value = "P5"
}
</script>
</body>
</html>
With the validation.js looking like this,
function validateForm()
{
var Location = document.forms["myForm"]["Location"].value;
var eName = document.forms["myform"]["eName"].value;
var datemin = document.forms["myform"]["datemin"].value;
var Time = document.forms["myform"]["Time"].value;
var Price = document.forms["myform"]["Price"].value;
var quantity = document.forms["myform"]["quantity"].value;
if(Location == "")
{
alert ("Please select a location.");
return false;
}
if(ename == "")
{
alert ("Please input an Event Name.");
return false;
}
if(datemin == "")
{
alert ("Please input the date of the event.");
return false;
}
if(Time == "")
{
alert ("Please input a Time for the event");
return false;
}
if(Price == "")
{
alert ("Please input a price.");
return false;
}
if(quantity == "")
{
alert ("Please input the amount of tickets you wish to purchase.");
return false;
}
else
{
return true;
}
}
Am I missing something, or doing something incorrectly? Thanks for any help!