Javascript onclick submit button issues - javascript

I'm working on validating user information via a form. I made a simple user information form and I cannot get the submit button to call the javascript fuction in the head. I do not know if I structured something incorrectly. I looked at the script in the head but I just cannot find the issue. Can someone help me find the issue with my submit button? Below, I have pasted my entire webpage for clarity.
<!DOCTYPE html>
<html>
<head>
<script>
alert("Hello, World!");
fucntion getResults()
{
var name = document.getElementById("name").value;
var address = document.getElementById("address").value;
var city = document.getElementById("city").value;
var gender = document.getElementById("gender").value;
var age = document.myform.age.option[document.myform.age.selectedIndex].value;
var state = document.myform.state.option[document.myform.state.selectedIndex].value;
var checkboxes = document.getElementsByName('box');
var selected = [];
for (var i=0; i<checkboxes.length; i++) {
if (checkboxes[i].checked) {
selected.push(checkboxes[i].value);
}
}
// var zip = document.getElementById("zip").vaule;
if(name == "")
{
alert("You must supply a full name!");
}
if(address == "")
{
alert("You must supply an address!");
}
if(city == "")
{
alert("You must supply a city!");
}
if(gender == "")
{
alert("You must supply a gender!");
}
if(age == "")
{
alert("You must supply an age!")
}
if(state == "")
{
alert("You must supply a state!")
}
if(selected.length < 1)
{
alert("You must supply a checked box for how you found my page!")
}
/* if(zip == "" || zip.length > 5 || /^[0-9]+$.test(zip))
{
alert("You must supply zip code!");
} */
document.getElementById("results").innerHTML = "Your name is " + name + ". You at this addresss " + address + "in this city " + city + "in this state " + state + ". Your gender is " + gender + ". You are " + age + "years old, and you found my webpage through this/these means " + selected.toString(); + "."
}
</script>
</head>
<body>
<form name="myform" id="myform">
<table border="3">
<tr>
<th>User Information Form</th>
</tr>
<tr>
<td>Full Name:</td>
<td>
<input type="text" id="name">
</td>
</tr>
<tr>
<td>Address:</td>
<td>
<input type="text" id="address">
</td>
</tr>
<tr>
<td>State:</td>
<td>
<select name="state" id="state">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</td>
</tr>
<tr>
<td>City:</td>
<td>
<input type="text" id="city">
</td>
</tr>
<!-- <tr>
<td>Zip Code:</td>
<td>
<input type="text" id="zip">
</td>
</tr> -->
<tr>
<td>Gender:</td>
<td>
Male: <input type="radio" name="gender" id="gender" value="male">
<br>
Female: <input type="radio" name="gender" id="gender" value="female">
<br>
Intersex: <input type="radio" name="gender" id="gender" value="intersex">
<br>
Other: <input type="radio" name="gender" id="gender" value="other">
</td>
</tr>
<tr>
<td>Age:</td>
<td>
<select>
<script>
for(i = 0; i < 101; i++)
{
document.writeln("<option value='" + i + "'>" + i + " </option>");
}
</script>
</select>
</td>
</tr>
<tr>
<td>How did you find my page?<br>(Check as many that apply)</td>
<td>
Friend:<input type="checkbox" id="box" value="friend">
<br>
Co-Worker:<input type="checkbox" id="box" value="coworker">
<br>
Family:<input type="checkbox" id="box" value="family">
<br>
Internet:<input type="checkbox" id="box" value="internet">
<br>
Maganize:<input type="checkbox" id="box" value="magazine">
<br>
Ad:<input type="checkbox" id="box" value="ad">
<br>
Other:<input type="checkbox" id="box" value="other">
<br>
</td>
</tr>
<tr>
<td>
<input type="button" value="Submit" onclick="getResults()">
</td>
<td>
<input type="reset" value="Reset">
</td>
</tr>
</table>
</form>
<p id="results"></p>
</body>
</html>

You have i typo error defining function getResults
just fix the function definition and i guess everything will be ok
Regards
Yes you have several others errors:
set form fields name
access them via respective names.
You can check my fix here
<!DOCTYPE html>
<html>
<head>
<script>
alert("Hello, World!");
function getResults()
{
var name = document.getElementById("name").value;
var address = document.getElementById("address").value;
var city = document.getElementById("city").value;
var gender = document.getElementById("gender").value;
var age = document.myform.age.value;
var state = document.myform.state.value;
var checkboxes = document.myform.referbox;
var selected = [];
for (var i=0; i<checkboxes.length; i++) {
if (checkboxes[i].checked) {
selected.push(checkboxes[i].value);
}
}
// var zip = document.getElementById("zip").vaule;
if(name == "")
{
alert("You must supply a full name!");
}
if(address == "")
{
alert("You must supply an address!");
}
if(city == "")
{
alert("You must supply a city!");
}
if(gender == "")
{
alert("You must supply a gender!");
}
if(age == "")
{
alert("You must supply an age!")
}
if(state == "")
{
alert("You must supply a state!")
}
if(selected.length < 1)
{
alert("You must supply a checked box for how you found my page!")
}
/* if(zip == "" || zip.length > 5 || /^[0-9]+$.test(zip))
{
alert("You must supply zip code!");
} */
document.getElementById("results").innerHTML = "Your name is " + name + ". You at this addresss " + address + "in this city " + city + "in this state " + state + ". Your gender is " + gender + ". You are " + age + "years old, and you found my webpage through this/these means " + selected.toString(); + "."
}
</script>
</head>
<body>
<form name="myform" id="myform">
<table border="3">
<tr>
<th>User Information Form</th>
</tr>
<tr>
<td>Full Name:</td>
<td>
<input type="text" id="name">
</td>
</tr>
<tr>
<td>Address:</td>
<td>
<input type="text" id="address">
</td>
</tr>
<tr>
<td>State:</td>
<td>
<select name="state" id="state">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</td>
</tr>
<tr>
<td>City:</td>
<td>
<input type="text" id="city">
</td>
</tr>
<!-- <tr>
<td>Zip Code:</td>
<td>
<input type="text" id="zip">
</td>
</tr> -->
<tr>
<td>Gender:</td>
<td>
Male: <input type="radio" name="gender" id="gender" value="male">
<br>
Female: <input type="radio" name="gender" id="gender" value="female">
<br>
Intersex: <input type="radio" name="gender" id="gender" value="intersex">
<br>
Other: <input type="radio" name="gender" id="gender" value="other">
</td>
</tr>
<tr>
<td>Age:</td>
<td>
<select name="age">
<script>
for(i = 0; i < 101; i++)
{
document.writeln("<option value='" + i + "'>" + i + " </option>");
}
</script>
</select>
</td>
</tr>
<tr>
<td>How did you find my page?<br>(Check as many that apply)</td>
<td>
Friend:<input type="checkbox" name="referbox" id="box" value="friend">
<br>
Co-Worker:<input type="checkbox" name="referbox" id="box" value="coworker">
<br>
Family:<input type="checkbox" name="referbox" id="box" value="family">
<br>
Internet:<input type="checkbox" name="referbox" id="box" value="internet">
<br>
Maganize:<input type="checkbox" name="referbox" id="box" value="magazine">
<br>
Ad:<input type="checkbox" name="referbox" id="box" value="ad">
<br>
Other:<input type="checkbox" name="referbox" id="box" value="other">
<br>
</td>
</tr>
<tr>
<td>
<input type="button" value="Submit" onclick="getResults()">
</td>
<td>
<input type="reset" value="Reset">
</td>
</tr>
</table>
</form>
<p id="results"></p>
</body>
</html>

You misspelled function as fucntion.
Hope that fixes it.

Change type="button" to type="submit".

Related

How to select only one row in table with checkbox

I have a table with x numbers of rows and 4 columns, one column is checkbox and other three are readonly selectboxs. I want the user to select just 1 row to be editable by checking checkbox in first column then if he check another checkbox in another row, the checkbox he previously checked get unchecked and row get readonly again.
So I want the user to select 1 row only to edit and others be readonly.
here is my code but it is not working.
$(document).ready(function(){
$('.col1, .col2, .col3').attr('disabled', true)
selectRow();
$('.tbl').on('change', '.selectRow', selectRow);
function selectRow() {
$('.tbl tbody tr').each(function () {
$(this).find('.selectRow').each(function () {
var checkedRow = $(this).closest('tr').find('input:checkbox:checked'),
col1 = $(this).closest('tr').find('.col1'),
col2 = $(this).closest('tr').find('.col2'),
col3 = $(this).closest('tr').find('col3');
if (checkedRow){
$('.col1, .col2, .col3').removeAttr('disabled')
checkedRow.siblings().prop('checked', false);
}else{
$('.col1, .col2, .col3').attr('disabled', true)
checkedRow.siblings().prop('checked', false);
}
});
});
}
});
<table class="tbl">
<tr>
<td><input type="checkbox" name="check1" class = "selectRow" /> </td>
<td>
<select class="col1">
<option id="col1o1">A</option>
<option id="col1o2">B</option>
<option id="col1o3">C</option>
<option id="col1o4">E</option>
</select>
</td>
<td>
<select class="col2">
<option id="col2o1">A</option>
<option id="col2o2">B</option>
<option id="col2o3">C</option>
<option id="col2o4">E</option>
</select>
</td>
<td>
<select class="col3">
<option id="col3o1">A</option>
<option id="col3o2">B</option>
<option id="col3o3">C</option>
<option id="col3o4">E</option>
</select>
</td>
</tr>
<br>
<tr>
<td><input type="checkbox" name="check1" /> </td>
<td>
<select class="s1">
<option id="s1o1">A</option>
<option id="o2">B</option>
<option id="o3">C</option>
<option id="o4">E</option>
</select>
</td>
<td>
<select class="s2">
<option id="s2o1">A</option>
<option id="s2o2">B</option>
<option id="s2o3">C</option>
<option id="s2o4">E</option>
</select>
</td>
<td>
<select class="s3">
<option id="s3o1">A</option>
<option id="s3o2">B</option>
<option id="s3o3">C</option>
<option id="s3o4">E</option>
</select>
</td>
</tr>
<br>
<tr>
<td><input type="checkbox" name="check1" /> </td>
<td>
<select class="s1">
<option id="s1o1">A</option>
<option id="o2">B</option>
<option id="o3">C</option>
<option id="o4">E</option>
</select>
</td>
<td>
<select class="s2">
<option id="s2o1">A</option>
<option id="s2o2">B</option>
<option id="s2o3">C</option>
<option id="s2o4">E</option>
</select>
</td>
<td>
<select class="s3">
<option id="s3o1">A</option>
<option id="s3o2">B</option>
<option id="s3o3">C</option>
<option id="s3o4">E</option>
</select>
</td>
</tr>
</table>
this is my code:
Without jQuery and using event delegation things may be somewhat simpler:
document.addEventListener(`click`, handle);
// disable all selectors initially
document.querySelectorAll(`td select`)
.forEach(s => s.setAttribute(`disabled`, true));
function handle(evt) {
// only do something if a checkbox was clicked
if (evt.target.type === `checkbox`) {
const isChecked = evt.target.checked;
const selectedRow = evt.target.closest(`tr`);
// reset checkboxes, row coloring and disabled state
document.querySelectorAll(`input[type='checkbox']`)
.forEach(cb => {
cb.checked = cb !== evt.target ? false : isChecked;
const row = cb.closest(`tr`);
row.classList[isChecked && row === selectedRow ?
`add` : `remove`](`selected`);
[...row.querySelectorAll(`select`)].filter(r => r !== selectedRow)
.forEach(s => s.setAttribute(`disabled`, true));
selectedRow.querySelectorAll(`select`)
.forEach(s => s[isChecked ?
`removeAttribute` : `setAttribute`](`disabled`, true));
});
}
}
body {
margin: 2rem;
}
tr.selected {
background-color: lightgreen;
}
<table class="tbl">
<tr>
<td><input type="checkbox" name="check1" class="selectRow" /> </td>
<td>
<select class="col1">
<option id="col1o1">A</option>
<option id="col1o2">B</option>
<option id="col1o3">C</option>
<option id="col1o4">E</option>
</select>
</td>
<td>
<select class="col2">
<option id="col2o1">A</option>
<option id="col2o2">B</option>
<option id="col2o3">C</option>
<option id="col2o4">E</option>
</select>
</td>
<td>
<select class="col3">
<option id="col3o1">A</option>
<option id="col3o2">B</option>
<option id="col3o3">C</option>
<option id="col3o4">E</option>
</select>
</td>
</tr>
<br>
<tr>
<td><input type="checkbox" name="check1" /> </td>
<td>
<select class="s1">
<option id="s1o1">A</option>
<option id="o2">B</option>
<option id="o3">C</option>
<option id="o4">E</option>
</select>
</td>
<td>
<select class="s2">
<option id="s2o1">A</option>
<option id="s2o2">B</option>
<option id="s2o3">C</option>
<option id="s2o4">E</option>
</select>
</td>
<td>
<select class="s3">
<option id="s3o1">A</option>
<option id="s3o2">B</option>
<option id="s3o3">C</option>
<option id="s3o4">E</option>
</select>
</td>
</tr>
<br>
<tr>
<td><input type="checkbox" name="check1" /> </td>
<td>
<select class="s1">
<option id="s1o1">A</option>
<option id="o2">B</option>
<option id="o3">C</option>
<option id="o4">E</option>
</select>
</td>
<td>
<select class="s2">
<option id="s2o1">A</option>
<option id="s2o2">B</option>
<option id="s2o3">C</option>
<option id="s2o4">E</option>
</select>
</td>
<td>
<select class="s3">
<option id="s3o1">A</option>
<option id="s3o2">B</option>
<option id="s3o3">C</option>
<option id="s3o4">E</option>
</select>
</td>
</tr>
</table>
Here's an even more simplified version, acting on the table rows
document.addEventListener(`click`, handle);
// create the table dynamically to keep demo lean
createTable();
function handle(evt) {
if (evt.target.type === `checkbox`) {
const selectedRow = evt.target.closest(`tr`);
document.querySelectorAll(`tr`)
.forEach( row => {
// not selected
if (row !== selectedRow) {
row.querySelector(`[type=checkbox]`).checked = false;
row.classList.remove(`selected`);
return row.querySelectorAll(`select`)
.forEach(s => s.setAttribute(`disabled`, true));
}
// selected
row.classList[[`remove`, `add`][+evt.target.checked]](`selected`);
row.querySelectorAll(`select`).forEach(s =>
s[`${[`set`,`remove`][+evt.target.checked]}Attribute`](`disabled`, true));
});
}
}
function createTable() {
const table = document.createElement(`table`);
const repeat = (str, n) => Array(n + 1).join(str);
const select = `<td><select>
<option>A</option>
<option>B</option>
<option>C</option>
<option>E</option></select></td>`;
const row = `<tr>
<td><input type="checkbox" /></td>
${repeat(select, 3)}</tr>`;
table.insertAdjacentHTML(`beforeend`, repeat(row, 3));
document.body.appendChild(table);
// disable all selectors initially
document.querySelectorAll(`td select`)
.forEach(s => s.setAttribute(`disabled`, true));
}
body {
margin: 2rem;
}
tr.selected {
background-color: lightgreen;
}
tr td:nth-child(1) {
padding-right: 6px;
}
The issue is because checkedRow holds a jQuery object. When you use that in an if condition it will always equate to true. You instead need to get the checked property from that element and use that in the condition instead.
Also note that the logic can be made much more succinct and extensible through the use of common selectors instead of incremental ones. In addition, you should look to add the disabled attribute to the HTML directly. Adding it via JS means that there will be a visible flash where the element is loaded as enabled, then when the DOM loads it will be disabled which is not good for your UX.
jQuery($ => {
selectRow();
$('.tbl').on('change', '.selectRow', selectRow);
function selectRow() {
$('.tbl tbody tr').each(function() {
let $row = $(this);
let $checkbox = $row.find('.selectRow');
$row.find('select').prop('disabled', !$checkbox.prop('checked'));
});
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="tbl">
<tr>
<td><input type="checkbox" name="check1" class="selectRow" /> </td>
<td>
<select class="col1" disabled="disabled">
<option id="col1o1">A</option>
<option id="col1o2">B</option>
<option id="col1o3">C</option>
<option id="col1o4">E</option>
</select>
</td>
<td>
<select class="col2" disabled="disabled">
<option id="col2o1">A</option>
<option id="col2o2">B</option>
<option id="col2o3">C</option>
<option id="col2o4">E</option>
</select>
</td>
<td>
<select class="col3" disabled="disabled">
<option id="col3o1">A</option>
<option id="col3o2">B</option>
<option id="col3o3">C</option>
<option id="col3o4">E</option>
</select>
</td>
</tr>
<br>
<tr>
<td><input type="checkbox" name="check1" class="selectRow" /> </td>
<td>
<select class="s1">
<option id="s1o1">A</option>
<option id="o2">B</option>
<option id="o3">C</option>
<option id="o4">E</option>
</select>
</td>
<td>
<select class="s2">
<option id="s2o1">A</option>
<option id="s2o2">B</option>
<option id="s2o3">C</option>
<option id="s2o4">E</option>
</select>
</td>
<td>
<select class="s3">
<option id="s3o1">A</option>
<option id="s3o2">B</option>
<option id="s3o3">C</option>
<option id="s3o4">E</option>
</select>
</td>
</tr>
<br>
<tr>
<td><input type="checkbox" name="check1" class="selectRow" /> </td>
<td>
<select class="s1">
<option id="s1o1">A</option>
<option id="o2">B</option>
<option id="o3">C</option>
<option id="o4">E</option>
</select>
</td>
<td>
<select class="s2">
<option id="s2o1">A</option>
<option id="s2o2">B</option>
<option id="s2o3">C</option>
<option id="s2o4">E</option>
</select>
</td>
<td>
<select class="s3">
<option id="s3o1">A</option>
<option id="s3o2">B</option>
<option id="s3o3">C</option>
<option id="s3o4">E</option>
</select>
</td>
</tr>
</table>
This works great! uncheck all checkboxes except the one having current focus '.tbl [type="checkbox"]:not(:focus)' then manipulate the select boxes
$(document).ready(function(){
$('.tbl [type="checkbox"]').on('click', function() {
$('.tbl [type="checkbox"]:not(:focus)').prop('checked', false);
$('.tbl select').attr('disabled', true);
$(this).parent().parent().find('select').attr('disabled', !$(this).prop('checked'));
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="tbl">
<tr>
<td><input type="checkbox" name="check1" class = "selectRow" /> </td>
<td>
<select class="col1" disabled>
<option id="col1o1">A</option>
<option id="col1o2">B</option>
<option id="col1o3">C</option>
<option id="col1o4">E</option>
</select>
</td>
<td>
<select class="col2" disabled>
<option id="col2o1">A</option>
<option id="col2o2">B</option>
<option id="col2o3">C</option>
<option id="col2o4">E</option>
</select>
</td>
<td>
<select class="col3" disabled>
<option id="col3o1">A</option>
<option id="col3o2">B</option>
<option id="col3o3">C</option>
<option id="col3o4">E</option>
</select>
</td>
</tr>
<br>
<tr>
<td><input type="checkbox" name="check1" /> </td>
<td>
<select class="s1" disabled>
<option id="s1o1">A</option>
<option id="o2">B</option>
<option id="o3">C</option>
<option id="o4">E</option>
</select>
</td>
<td>
<select class="s2" disabled>
<option id="s2o1">A</option>
<option id="s2o2">B</option>
<option id="s2o3">C</option>
<option id="s2o4">E</option>
</select>
</td>
<td>
<select class="s3" disabled>
<option id="s3o1">A</option>
<option id="s3o2">B</option>
<option id="s3o3">C</option>
<option id="s3o4">E</option>
</select>
</td>
</tr>
<br>
<tr>
<td><input type="checkbox" name="check1" /> </td>
<td>
<select class="s1" disabled>
<option id="s1o1">A</option>
<option id="o2">B</option>
<option id="o3">C</option>
<option id="o4">E</option>
</select>
</td>
<td>
<select class="s2" disabled>
<option id="s2o1">A</option>
<option id="s2o2">B</option>
<option id="s2o3">C</option>
<option id="s2o4">E</option>
</select>
</td>
<td>
<select class="s3" disabled>
<option id="s3o1">A</option>
<option id="s3o2">B</option>
<option id="s3o3">C</option>
<option id="s3o4">E</option>
</select>
</td>
</tr>
</table>

Using a cookie to store data

I'm in the process of creating a login and register page for an website. I decided to use a cookie to store the registered data rather than using PHP. How exactly I would do this? I have basic details like firstname, surname, birthday, username, email and password. I want to store the details so when the user registers with the site, they can then login with what they have registered with. This is all done in a form which is below:
<form action="" method="post" name="form1" onsubmit="getdropdownvalue()">
<table bgcolor="white" width="700" border="0" align="center">
<col width="200">
<col width="200">
<tr>
<th colspan="2" align="center" bgcolor="grey">Fill the form to sign up.</th>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td colspan="2" style="font-size:12px">Fields marked with * are mandatory</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>Name*</td>
<td>Surname*</td>
</tr>
<tr>
<td>
<label>
<input type="text" name="txtname" id="txtname" class="info" />
<td>
<label>
<input type="text" name="txtsurname" id="txtsurname" class="info" />
</label>
</td>
</tr>
<tr>
<td>Create Username*</td>
<td>Birthday</td>
</tr>
<tr>
<td>
<label>
<input type="text" name="txtusername" id="txtusername" class="info" />
</label>
</td>
<td>
<select name="DOBMonth">
<option>Month</option>
<option value="January">January</option>
<option value="Febuary">Febuary</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
<select name="DOBDay">
<option>Day</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select name="DOBYear">
<option>Year</option>
<option value="2016">2016</option>
<option value="2015">2015</option>
<option value="2014">2014</option>
<option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
<option value="1999">1998</option>
<option value="1998">1998</option>
<option value="1997">1997</option>
<option value="1996">1996</option>
<option value="1995">1995</option>
<option value="1994">1994</option>
<option value="1993">1993</option>
<option value="1992">1992</option>
<option value="1991">1991</option>
<option value="1990">1990</option>
<option value="1989">1989</option>
<option value="1988">1988</option>
<option value="1987">1987</option>
<option value="1986">1986</option>
<option value="1985">1985</option>
<option value="1984">1984</option>
<option value="1983">1983</option>
<option value="1982">1982</option>
<option value="1981">1981</option>
<option value="1980">1980</option>
<option value="1979">1979</option>
<option value="1978">1978</option>
<option value="1977">1977</option>
<option value="1976">1976</option>
<option value="1975">1975</option>
<option value="1974">1974</option>
<option value="1973">1973</option>
<option value="1972">1972</option>
<option value="1971">1971</option>
<option value="1970">1970</option>
<option value="1969">1969</option>
<option value="1968">1968</option>
<option value="1967">1967</option>
<option value="1966">1966</option>
<option value="1965">1965</option>
<option value="1964">1964</option>
<option value="1963">1963</option>
<option value="1962">1962</option>
<option value="1961">1961</option>
<option value="1960">1960</option>
<option value="1959">1959</option>
<option value="1958">1958</option>
<option value="1957">1957</option>
<option value="1956">1956</option>
<option value="1955">1955</option>
<option value="1954">1954</option>
<option value="1953">1953</option>
<option value="1952">1952</option>
<option value="1951">1951</option>
<option value="1950">1950</option>
<option value="1949">1949</option>
<option value="1948">1948</option>
<option value="1947">1947</option>
</select>
<tr>
<td>Email*</td>
<td>Confirm Email*</td>
</tr>
<tr>
<td>
<label>
<input type="text" name="txtemail" id="txtemail" class="info" onchange="ValidateEmail(txtemail)" />
<td>
<label>
<input type="text" name="txtemail2" id="txtemail2" class="info" onchange="ValidateEmail2(txtemail2)" />
</label>
</td>
</tr>
<tr>
<td>Password*</td>
<td>Confirm Pasword*</td>
</tr>
<tr>
<td>
<label>
<input type="password" name="txtpassword" id="txtpassword" class="info" />
<td>
<label>
<input type="password" name="txtpassword2" id="txtpassword2" class="info" />
</label>
</td>
</tr>
<td colspan="2" style="font-size:12px">**Passwords must be at least 8 characters in lenght.</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td colspan="2">
<label>
<input type="radio" name="terms" value="terms" id="terms" />I agree to the Terms and Conditions</label>
</td>
</tr>
<br>
<br>
<br>
<tr>
<td colspan="2">
<label>
<input type="radio" name="notify" value="notify" id="notify" />I want to receive notifications by text/email about new products in stock.</label>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>
<label>
<input type="submit" name="Login" id="Login" value="Login" onclick="checkdetails()" />
</label>
</td>
<td>
<label>
<input type="reset" name="Reset" id="Reset" value="Reset" />
</label>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</form>
How can I achieve this? Any suggestions?
If you would like to save form data within a cookie (which is not recommended as stated in the comments), you will have to use JavaScript like this:
<script type="text/javascript">
var today = new Date();
var expiry = new Date(today.getTime() + 30 * 24 * 3600 * 1000); // plus 30 days
function setCookie(name, value)
{
document.cookie=name + "=" + escape(value) + "; path=/; expires=" + expiry.toGMTString();
}
function storeValues(form)
{
setCookie("field1", form.field1.value);// replace with your form fields
setCookie("field2", form.field2.value);
setCookie("field3", form.field3.value);
setCookie("field4", form.field4.value);
return true;
}
</script>
Also, you will need to call the setCookie function by calling it when the form's submit button is clicked, like this:
<input type="submit" onclick="storeValues(this.form)" value="Submit" />

Password validation for javascript

Hey I have a password validation function that I'm having trouble with. I have it working so that the user is immediately warned when the passwords don't match. However, I also want it to state that the password should have letters and numbers, and it can't be less than 6 characters. No matter what way I do it it won't work. Here is what I have that works so i just need help adding the rest. Thanks
<head>
function checkpass(pass1,pass2)
{
pass1=document.getElementById("txtpassword").value;
pass2=document.getElementById("txtpassword2").value;
if (pass1 != pass2)
{
alert ("Passwords must match");
}
}
</head>
<body>
<form action="Home.html" method="post" name="form1" onsubmit="Display()">
<table bgcolor="white" width="700" border="0" align="center">
<col width="200">
<col width="200">
<tr>
<th colspan = "2" align = "center" bgcolor="grey"> Fill the form to sign up. </th>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>Forename</td>
<td>Surname</td>
</tr>
<tr>
<td><label>
<input type="text" name="txtname" id="txtname" class="info" required>
<td><label>
<input type="text" name="txtsurname" id="txtsurname" class="info" required />
</label></td>
</tr>
<tr>
<td> Create Username</td>
<td> Birthday</td>
</tr>
<tr>
<td><label>
<input type="text" name="txtusername" id="txtusername" class="info" required/>
</label></td>
<td><select name="DOBMonth" required>
<option value=""> Month </option>
<option value="January">January</option>
<option value="Febuary">Febuary</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
<select name="DOBDay" required>
<option value=""> Day </option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select name="DOBYear" required>
<option value=""> Year </option>
<option value="2016">2016</option>
<option value="2015">2015</option>
<option value="2014">2014</option>
<option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
<option value="1999">1998</option>
<option value="1998">1998</option>
<option value="1997">1997</option>
<option value="1996">1996</option>
<option value="1995">1995</option>
<option value="1994">1994</option>
<option value="1993">1993</option>
<option value="1992">1992</option>
<option value="1991">1991</option>
<option value="1990">1990</option>
<option value="1989">1989</option>
<option value="1988">1988</option>
<option value="1987">1987</option>
<option value="1986">1986</option>
<option value="1985">1985</option>
<option value="1984">1984</option>
<option value="1983">1983</option>
<option value="1982">1982</option>
<option value="1981">1981</option>
<option value="1980">1980</option>
<option value="1979">1979</option>
<option value="1978">1978</option>
<option value="1977">1977</option>
<option value="1976">1976</option>
<option value="1975">1975</option>
<option value="1974">1974</option>
<option value="1973">1973</option>
<option value="1972">1972</option>
<option value="1971">1971</option>
<option value="1970">1970</option>
<option value="1969">1969</option>
<option value="1968">1968</option>
<option value="1967">1967</option>
<option value="1966">1966</option>
<option value="1965">1965</option>
<option value="1964">1964</option>
<option value="1963">1963</option>
<option value="1962">1962</option>
<option value="1961">1961</option>
<option value="1960">1960</option>
<option value="1959">1959</option>
<option value="1958">1958</option>
<option value="1957">1957</option>
<option value="1956">1956</option>
<option value="1955">1955</option>
<option value="1954">1954</option>
<option value="1953">1953</option>
<option value="1952">1952</option>
<option value="1951">1951</option>
<option value="1950">1950</option>
<option value="1949">1949</option>
<option value="1948">1948</option>
<option value="1947">1947</option>
</select>
<tr>
<td>Email</td>
<td>Confirm Email</td>
</tr>
<tr>
<td><label>
<input type="text" name="txtemail" id="txtemail" class="info" onchange="ValidateEmail(txtemail)" required />
<td><label>
<input type="text" name="txtemail2" id="txtemail2" class="info" onchange="ValidateEmail2(txtemail2)" required/>
</label></td>
</tr>
<tr>
<td>Password</td>
<td>Confirm Pasword</td>
</tr>
<tr>
<td><label>
<input type="password" name="txtpassword" id="txtpassword" class="info" required/>
<td><label>
<input type="password" name="txtpassword2" id="txtpassword2" class="info" required/ onchange="checkpass(txtpassword,txtpassword2)">
</label></td>
</tr>
<td colspan="2" style="font-size:12px">**Passwords must be at least 8 characters in length.</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td colspan="2">
<label>
<input type="checkbox" name="terms" value="terms" id="terms" required/>
I agree to the Terms and Conditions</label>
</td></tr>
<br><br><br>
<tr>
<td colspan="2"><label>
<input type="checkbox" name="notify" value="notify" id="notify" />
I want to receive notifications by text/email about new products in stock.</label>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><label>
<input type="submit" name="Login" id="Login" value="Login"/>
</label></td>
<td><label>
<input type="reset" name="Reset" id="Reset" value="Reset" />
</label></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</form>
</body>
Here is the code
function checkpass() {
var pass1=document.getElementById("txtpassword").value;
var pass2=document.getElementById("txtpassword2").value;
if (pass1 !== pass2) {
alert ("Passwords must match");
} else if (pass1.length < 6) {
// too short
} else if (!/[0-9]/.test(pass1)) {
// no digit
} else if (!/[A-Za-z]/.test(pass1)) {
// no character
} else {
return true; // return true when password matched rules
}
return false; // false otherwise
}

Javascript Travel Calculator not working

I'm trying to make a JavaScript calculator that will calculate the cost for 4 families to travel by train. The cost for one adult ticket is $32 and the cost for a child is $20 with a $10 commission fee. This is my JavaScript. When i run it in Firefox debugger it says amountdue1 is not defined?
<script language="JavaScript/text">
var child = 20;
var adult = 32;
function amountdue1() {
{
if (document.calc.familyname1.value === null || document.calc.familyname1.value.length === 0)
{
alert("Please enter your family name");
}
else
{
var numadults = document.calc.num_Adults1.selectedIndex;
var numchildren = document.calc.num_Children1.selectedIndex;
document.calc.totaldue.value = (numadults * adult) + (numchildren * child) + 10;
}};
this table is in the body. There would be 4 amountdue(s) but i couldn't get one to work.
<table width=100% border=1 class="one" id="table_one">
<br>
<tr>
<th width=20%>Family One</th>
<th width=20%>Family Two</th>
<th width=20%>Family Three</th>
<th width=20%>Family Four</th>
</tr>
<tr>
<td align=center>
<br>
<input type="text" name="familyname1" maxlength="20"><br>
</td>
<td align=center>
<br>
<input type="text" name="familyname2" maxlength="20"><br>
</td>
<td align=center>
<br>
<input type="text" name="familyname3" maxlength="20">
</td>
<td align=center>
<br>
<input type="text" name="familyname4" maxlength="20"><br>
</tr>
<tr>
<td align=center><br>
<select id="num_Adults1" onchange="return total1()">
<option value=0 selected>0 Adults</option>
<option value=1>1 Adult</option>
<option value=1>2 Adults</option>
<option value=1>3 Adults</option>
<option value=1>4 Adults</option>
<option value=1>5 Adults</option>
<option value=1>6 Adults</option>
<option value=1>7 Adults</option>
<option value=1>8 Adults</option>
</select>
</td>
<td align=center><br>
<select id="num_Adults2" onchange="return total2()">
<option value=0 selected>0 Adults</option>
<option value=1>1 Adult</option>
<option value=1>2 Adults</option>
<option value=1>3 Adults</option>
<option value=1>4 Adults</option>
<option value=1>5 Adults</option>
<option value=1>6 Adults</option>
<option value=1>7 Adults</option>
<option value=1>8 Adults</option>
</select>
</td>
<td align=center><br>
<select id="num_Adults3" onchange="return total3()">
<option value=0 selected>0 Adults</option>
<option value=1>1 Adult</option>
<option value=1>2 Adults</option>
<option value=1>3 Adults</option>
<option value=1>4 Adults</option>
<option value=1>5 Adults</option>
<option value=1>6 Adults</option>
<option value=1>7 Adults</option>
<option value=1>8 Adults</option>
</select>
</td>
<td align=center><br>
<select id="num_Adults4" onchange="return total4()">
<option value=0 selected>0 Adults</option>
<option value=1>1 Adult</option>
<option value=1>2 Adults</option>
<option value=1>3 Adults</option>
<option value=1>4 Adults</option>
<option value=1>5 Adults</option>
<option value=1>6 Adults</option>
<option value=1>7 Adults</option>
<option value=1>8 Adults</option>
</select>
</td>
</tr>
<tr>
<td align=center><br>
<select id="num_Children1" onchange="return total1()">
<option value=0 selected>0 Children</option>
<option value=1>1 Child</option>
<option value=1>2 Children</option>
<option value=1>3 Children</option>
<option value=1>4 Children</option>
<option value=1>5 Children</option>
<option value=1>6 Children</option>
<option value=1>7 Children</option>
<option value=1>8 Children</option>
</select>
</td>
<td align=center>
<br>
<select id="num_Children2" onchange="return total2()">
<option value=0 selected>0 Children</option>
<option value=1>1 Child</option>
<option value=1>2 Children</option>
<option value=1>3 Children</option>
<option value=1>4 Children</option>
<option value=1>5 Children</option>
<option value=1>6 Children</option>
<option value=1>7 Children</option>
<option value=1>8 Children</option>
</select>
</td>
<td align=center><br>
<select id="num_Children3" onchange="return total3()">
<option value=0 selected>0 Children</option>
<option value=1>1 Child</option>
<option value=1>2 Children</option>
<option value=1>3 Children</option>
<option value=1>4 Children</option>
<option value=1>5 Children</option>
<option value=1>6 Children</option>
<option value=1>7 Children</option>
<option value=1>8 Children</option>
</select>
</td>
<td align=center><br>
<select id="num_Children4" onchange="return total4()">
<option value=0 selected>0 Children</option>
<option value=1>1 Child</option>
<option value=1>2 Children</option>
<option value=1>3 Children</option>
<option value=1>4 Children</option>
<option value=1>5 Children</option>
<option value=1>6 Children</option>
<option value=1>7 Children</option>
<option value=1>8 Children</option>
</select>
</td>
</tr>
<tr>
<td align=center>
<input type=button onclick="amountdue1()" name="total1" value="Find total">
<input type=reset value=Reset>
<br><br>
<input type="text" name="totaldue" size=15 readonly title="Total Amount" maxlength="9" placeholder="$">
</td>
<td align=center>
<input type=button onclick="total2()" value="Find total">
<input type=reset value=Reset>
<br><br>
<input type="text" name="totaldue2" size=15 readonly title="Total Amount" maxlength="9" placeholder="$">
</td>
<td align=center>
<input type=button onclick="total3()" value="Find total">
<input type=reset value=Reset>
<br><br>
<input type="text" name="totaldue3" size=15 readonly title="Total Amount" maxlength="9" placeholder="$">
</td>
<td align=center>
<input type=button onclick="total4()" value="Find total">
<input type=reset value=Reset>
<br><br>
<input type="text" name="totaldue4" size=15 readonly title="Total Amount" maxlength="9" placeholder="$">
</td>
</tr>
</table>
function amountdue1()
{
if (document.calc.familyname1.value === null || document.calc.familyname1.value.length === 0)
{
alert("Please enter your family name");
}
else
{
var numadults = document.calc.num_Adults1.selectedIndex;
var numchildren = document.calc.num_Children1.selectedIndex;
document.calc.totaldue.value = (numadults * adult) + (numchildren * child) + 10;
}}
You have added extra curly brace inthe function.Also,the function wont end with semi colon.Please check the updated one
I think the problem is the script tag <script language="JavaScript/text">, Looks like browser is not parsing your script element.
<script language="javascript">
The language attribute of script does not have any standard values and it is deprecated also you can simply omit it. Or you can use the type attribute <script type="text/javascript">

inserting data in mysql using GET method and populating text field on client side

Below is my code for the admin panel where I have used ajax for populating the text field from selected drop down menu on the client side. Please suggest me solutions for the two issues:
Form 'issue': On submitting, it should insert data into the database. But I think there's some problem with the $_GET['submit1'].
Form 'return_form': I m trying to populate the text box 'charges' on the basis of value of 'days' text box entered. But no value obtained either by using 'onfocus()' or 'onblur()'.
Thanks in advance for the suggestions.
<script type="text/javascript">
function func1()
{
var req;
try
{
req= new XMLHttpRequest();
}
catch(e)
{
try
{
req= new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
req= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
alert("Something went wrong..!!");
return false;
}
}
}
req.onreadystatechange= function()
{
if(req.readyState==4)
{
var result= req.responseText;
var string= result.split('-');
document.issue.cost.value= string[0];
document.issue.rent.value= string[1];
}
}
var book= document.getElementById('book').value;
var app_query= "?book="+book;
req.open("GET","issue_form.php"+app_query,true);
req.send(null);
}
function func2()
{
var req;
try
{
req= new XMLHttpRequest();
}
catch(e)
{
try
{
req= new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
req= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
alert("Something went wrong..!!");
return false;
}
}
}
req.onreadystatechange= function()
{
if(req.readyState==4)
{
var result= req.responseText;
var string= result.split('-');
document.return_form.iss_yr.value= string[0];
var month= string[1];
/*switch(month)
{
case 01: month="Jan";
break;
case 02: month="Feb";
break;
case 03: month="Mar";
break;
case 04: month="Apr";
break;
case 05: month="May";
break;
case 06: month="June";
break;
case 07: month="July";
break;
case 08: month="Aug";
break;
case 09: month="Sep";
break;
case 10: month="Oct";
break;
case 11: month="Nov";
break;
case 12: month="Dec";
break;
default: alert("Invalid...!!");
}*/
document.return_form.iss_mnth.value= month;
document.return_form.iss_date.value= string[2];
document.return_form.cost2.value= string[3];
document.return_form.rent2.value= string[4];
}
}
var book= document.getElementById('books').value;
var app_query= "?book="+book;
req.open("GET","return_form.php"+app_query,true);
req.send(null);
}
function func3()
{
var req;
try
{
req= new XMLHttpRequest();
}
catch(e)
{
try
{
req= new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
req= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
alert("Something went wrong..!!");
return false;
}
}
}
req.onreadystatechange= function()
{
if(req.readyState==4)
{
var result= req.responseText;
document.return_form.charges.value= result;
}
}
var rent= document.getElementById('rent2').value;
var days= document.getElementById('days').value;
var app_query= "?rent2="+rent+"days="+days;
req.open("GET","calc_charges.php"+app_query,true);
req.send(null);
}
</script>
</head>
<body>
<?php
include('connect.php');
?>
<div class="style1">
<form name="issue" action="" method="get" style="margin-top:25%">
<fieldset style="width:700px; height:400px; margin-left:25%; border-color:#044146;">
<legend style="font-size:24px; font-family:'Comic Sans MS', cursive; font-weight:bolder; color:#0D5C6A;">Issue A Book</legend>
<table align="center" border="1" class="style2" height="270px" width="500px" style="margin-top:50px;">
<tr>
<td>Book: </td>
<td>
<select name="book" id="book" onchange="func1()" style="width:250px;">
<option value="" selected="selected">---select---</option>
<?php
$query1= mysql_query("select book_name from books");
while($books= mysql_fetch_array($query1))
{
echo '<option>';
echo $books['book_name'];
echo '</option>';
}
?>
</select>
</td>
</tr>
<tr>
<td>Date of Issue: </td>
<td>
<select name="issue_date" id="issue_date">
<option value="DD">DD</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select name="issue_month" id="issue_month">
<option value="MM">MM</option>
<option value="01">Jan</option>
<option value="02">Feb</option>
<option value="03">Mar</option>
<option value="04">Apr</option>
<option value="05">May</option>
<option value="06">Jun</option>
<option value="07">Jul</option>
<option value="08">Aug</option>
<option value="09">Sep</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select>
<select name="issue_year" id="issue_year">
<option value="YYYY">YYYY</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
<option value="2022">2022</option>
<option value="2023">2023</option>
<option value="2024">2024</option>
<option value="2025">2025</option>
<option value="2026">2026</option>
<option value="2027">2027</option>
<option value="2028">2028</option>
<option value="2029">2029</option>
<option value="2030">2030</option>
</select>
</td>
</tr>
<tr>
<td>Cost: </td>
<td><input type="text" name="cost" style="width:240px;" readonly="readonly" /></td>
</tr>
<tr>
<td>Rent_per_day: </td>
<td><input type="text" name="rent" style="width:240px;" readonly="readonly" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit1" value="Submit" class="style5" /></td>
</tr>
</table>
</fieldset>
</form>
<form name="return_form" action="" method="get" style="margin-top:5%">
<fieldset style="width:700px; height:490px; margin-left:25%; border-color:#044146;">
<legend style="font-size:24px; font-family:'Comic Sans MS', cursive; font-weight:bolder; color:#0D5C6A;">Return A Book</legend>
<table align="center" border="1" class="style2" height="350px" width="500px" style="margin-top:50px;">
<tr>
<td>Book: </td>
<td>
<select name="books" id="books" onchange="func2()" style="width:250px;">
<option value="" selected="selected">---select---</option>
<?php
$query2= mysql_query("select book_issued from member_activity_log");
while($books= mysql_fetch_array($query2))
{
echo '<option>';
echo $books['book_issued'];
echo '</option>';
}
?>
</select>
</td>
</tr>
<tr>
<td>Date of Issue: </td>
<td><input type="text" name="iss_date" style="width:40px;" readonly="readonly" />
<input type="text" name="iss_mnth" style="width:40px;" readonly="readonly" />
<input type="text" name="iss_yr" style="width:45px;" readonly="readonly" /></td>
</tr>
<tr>
<td>Cost: </td>
<td><input type="text" name="cost2" style="width:240px;" readonly="readonly" /></td>
</tr>
<tr>
<td>Rent_per_day: </td>
<td><input type="text" name="rent2" style="width:240px;" readonly="readonly" /></td>
</tr>
<tr>
<td>Date of Return: </td>
<td>
<select name="return_date" id="return_date">
<option value="DD">DD</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select name="return_month" id="return_month">
<option value="MM">MM</option>
<option value="01">Jan</option>
<option value="02">Feb</option>
<option value="03">Mar</option>
<option value="04">Apr</option>
<option value="05">May</option>
<option value="06">Jun</option>
<option value="07">Jul</option>
<option value="08">Aug</option>
<option value="09">Sep</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select>
<select name="return_year" id="return_year">
<option value="YYYY">YYYY</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
<option value="2022">2022</option>
<option value="2023">2023</option>
<option value="2024">2024</option>
<option value="2025">2025</option>
<option value="2026">2026</option>
<option value="2027">2027</option>
<option value="2028">2028</option>
<option value="2029">2029</option>
<option value="2030">2030</option>
</select>
</td>
</tr>
<tr>
<td>No. of Days: </td>
<td><input type="text" name="days" style="width:240px;" onblur="func3()"/></td>
</tr>
<tr>
<td>Charges: </td>
<td><input type="text" name="charges" style="width:240px;" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit2" value="Submit" class="style5" /></td>
</tr>
</table>
</fieldset>
</form>
</div>
<?php
$reg_no= $_GET['id'];
if(isset($_GET['submit1']))
{
$book_name= $_GET['book'];
$dd= $_GET['issue_date'];
$mm= $_GET['issue_month'];
$yyyy= $_GET['issue_year'];
$date= $yyyy."-".$mm."-".$dd;
$cost= $_GET['cost'];
$rent_per_day= $_GET['rent'];
$insert_query= mysql_query("insert into member_activity_log(book_issued,date_of_issue,cost,rent_per_day) values('".$book_name."','".$date."','".$cost."','".$rent_per_day."') where reg_no='$reg_no'");
if($insert_query)
{
header("Location: member_activity_log.php");
}
else
{
echo "Error...!!";
}
}
?>
</body>
</html>

Categories