I am trying to insert multiple rows of data from my form into my sql database. I have been looking up arrays and been trying to apply what I have found but to no avail. I am beginner to programming never took any formal classes, been learning snipits of code as I need, so my fundamentals are nonexistent.
PlayerID is not auto-increment but an actually number provided by the user.
Here is my form code
<table border="1">
<tr>
<td align="center">Form Input Employees Data</td>
</tr>
<tr>
<td>
<table>
<form method="post" action="/wp/wp-content/plugins/FormSubmit/FSdotaArray.php">
<tr>
<td></td>
<td><b>Captain</b></td>
</tr>
<tr>
<td>Steam ID</td>
<td><input type="text" name="playerid" size="20">
</td>
</tr>
<tr>
<td>Fisrt Name</td>
<td><input type="text" name="firstname" size="20">
</td>
</tr>
<tr>
<td>last Name</td>
<td><input type="text" name="lastname" size="20">
</td>
</tr>
<tr>
<td>Position</td>
<td><select name="position">
<option value="1:hardcarry">1: Hard Carry</option>
<option value="2:mid">2: Mid</option>
<option value="3:offlane">3: Offlane</option>
<option value="4:support">4: Support</option>
<option value="5:support">5: Support</option>
</select>
</td>
</tr>
<tr>
<td>Team</td>
<td><input type="text" name="team" size="40">
</td>
</tr>
<tr>
<td>Game</td>
<td><select name="game">
<option value="dota2">Dota 2</option>
<option value="leagueoflegends">League of Legends</option>
<option value="starcraft2">StarCraft 2: Heart of the Swarm</option>
<option value="USFIV">USFIV</option>
</select>
</td>
</tr>
<td></td>
<td><b>Player 2</b></td>
</tr>
<tr>
<td>Steam ID</td>
<td><input type="text" name="playerid" size="20">
</td>
</tr>
<tr>
<td>Fisrt Name</td>
<td><input type="text" name="firstname" size="20">
</td>
</tr>
<tr>
<td>last Name</td>
<td><input type="text" name="lastname" size="20">
</td>
</tr>
<tr>
<td>Position</td>
<td><select name="position">
<option value="1:hardcarry">1: Hard Carry</option>
<option value="2:mid">2: Mid</option>
<option value="3:offlane">3: Offlane</option>
<option value="4:support">4: Support</option>
<option value="5:support">5: Support</option>
</select>
</td>
</tr>
<tr>
<td>Team</td>
<td><input type="text" name="team" size="40">
</td>
</tr>
<tr>
<td>Game</td>
<td><select name="game">
<option value="dota2">Dota 2</option>
<option value="leagueoflegends">League of Legends</option>
<option value="starcraft2">StarCraft 2: Heart of the Swarm</option>
<option value="USFIV">USFIV</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td align="right"><input type="submit" name="submit" value="Sent"></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
Here is my php code, The header is needed because I am using wordpress and running the code as a plugin.
<?php
/*
Plugin Name: FSdota
Description: submit form data into sql database
Author: F. May
Version: 1.0
*/
//inserting data order
$con=mysqli_connect("XXXXXX","XXXXXXXX","XXXXXXXX","XXXXXXXX");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysqli_query($con,"XXXXXXXXXX");
$row_data = "($playerid,$firstname, $lastname, $position,$team,$Game)";
if (is_array($row_data));
{
foreach($_POST['playerid'] as $row=>$playerid) {
$playerid = mysqli_real_escape_string('playerid');
$firstname = mysqli_real_escape_string($con,($_POST['firstname'][$row]));
$lastname = mysqli_real_escape_string($con,($_POST['lastname'][$row]));
$position = mysqli_real_escape_string($con,($_POST['position'][$row]));
$team = mysqli_real_escape_string($con,($_POST['team'][$row]));
$game = mysqli_real_escape_string($con,($_POST['game'][$row]));
}
}
if (!empty($row_data)) {
$sql="INSERT INTO wp_es_fstest (PlayerID,FirstName,LastName,Position,Team,Game) VALUES".implode(',', $row_data);
$query = mysqli_query($con, $sql);
if (mysql_query($query))
echo 'Successful inserts: ' . mysql_affected_rows($con);
else
echo 'query failed';
}
?>
You are not sending multiple values for the same fields. Your name attributes are like name="playerid" so that means that every new entry with the same name will overwrite the previous one and only one gets sent to the server.
You should use arrays to group your fields:
<input type="text" name="playerid[SOME_ID]" size="20">
...
<input type="text" name="firstname[SOME_ID]" size="20">
...
// etc.
...
<input type="text" name="playerid[SOME_OTHER_ID]" size="20">
...
<input type="text" name="firstname[SOME_OTHER_ID]" size="20">
...
// etc.
For the SOME_ID, SOME_OTHER_ID, etc. values you could use a value from a database if it already exist or a simple counter, as long as the fields in a group use the same number / ID.
About the php-side, as mentioned by #Fred-ii- you should only use one sql API, in this case mysqli.
Also note that:
$playerid = mysqli_real_escape_string('playerid');
should be:
$playerid = mysqli_real_escape_string($con, 'playerid');
Personally I would also use a prepared statement with bound variables so that you can prepare your statement once and then run it several times with the different groups of values without having to worry about sql injection / escaping the values.
One additional remark:
This is going to fail:
$row_data = "($playerid,$firstname, $lastname, $position,$team,$Game)";
if (is_array($row_data));
{
You have just set your $row_data variable to be a string, probably with a bunch of undefined variables so checking one line after that whether it is an array is never going to work.
Alright so it has been a while since the last point, life got busy and I wanted to do a little more research.
I have modified my form.html to specify that they are arrays and created a new php file to go with it. here is the code below.
<body>
<table border="1">
<tr>
<td align="center">Dota 2 Open Team Registration</td>
</tr>
<tr>
<td>
<table>
<form method="post" action="/wp/wp-content/plugins/FormSubmit/FSdotaArray.php">
<tr>
<td></td>
<td><b>Captain</b></td>
</tr>
<tr>
<td>Steam ID</td>
<td><input type="text" name="playerid[playerid_1]" size="20">
</td>
</tr>
<tr>
<td>Fisrt Name</td>
<td><input type="text" name="firstname[firstname_1]" size="20">
</td>
</tr>
<tr>
<td>last Name</td>
<td><input type="text" name="lastname[lastname_1]" size="20">
</td>
</tr>
<tr>
<td>Position</td>
<td><select name="position[position_1]">
<option value="1:hardcarry">1: Hard Carry</option>
<option value="2:mid">2: Mid</option>
<option value="3:offlane">3: Offlane</option>
<option value="4:support">4: Support</option>
<option value="5:support">5: Support</option>
</select>
</td>
</tr>
<tr>
<td>Team</td>
<td><input type="text" name="team[team_1]" size="40">
</td>
</tr>
<tr>
<td>Game</td>
<td><select name="game[game_1]">
<option value="dota2">Dota 2</option>
<option value="leagueoflegends">League of Legends</option>
<option value="starcraft2">StarCraft 2: Heart of the Swarm</option>
<option value="USFIV">USFIV</option>
</select>
</td>
</tr>
<!-- Player 2 -->
<td></td>
<td><b>Player 2</b></td>
</tr>
<tr>
<td>Steam ID</td>
<td><input type="text" name="playerid[player_2]" size="20">
</td>
</tr>
<tr>
<td>Fisrt Name</td>
<td><input type="text" name="firstname[firstname_2]" size="20">
</td>
</tr>
<tr>
<td>last Name</td>
<td><input type="text" name="lastname[lastname_2]" size="20">
</td>
</tr>
<tr>
<td>Position</td>
<td><select name="position[position_2]">
<option value="1:hardcarry">1: Hard Carry</option>
<option value="2:mid">2: Mid</option>
<option value="3:offlane">3: Offlane</option>
<option value="4:support">4: Support</option>
<option value="5:support">5: Support</option>
</select>
</td>
</tr>
<tr>
<td>Team</td>
<td><input type="text" name="team[team_2]" size="40">
</td>
</tr>
<tr>
<td>Game</td>
<td><select name="game[game_2]">
<option value="dota2">Dota 2</option>
<option value="leagueoflegends">League of Legends</option>
<option value="starcraft2">StarCraft 2: Heart of the Swarm</option>
<option value="USFIV">USFIV</option>
</select>
</td>
</tr>
<!--Player 3 -->
<td></td>
<td><b>Player 3</b></td>
</tr>
<tr>
<td>Steam ID</td>
<td><input type="text" name="playerid[player_3]" size="20">
</td>
</tr>
<tr>
<td>Fisrt Name</td>
<td><input type="text" name="firstname[firstname_3]" size="20">
</td>
</tr>
<tr>
<td>last Name</td>
<td><input type="text" name="lastname[lastname_3]" size="20">
</td>
</tr>
<tr>
<td>Position</td>
<td><select name="position[position_3]">
<option value="1:hardcarry">1: Hard Carry</option>
<option value="2:mid">2: Mid</option>
<option value="3:offlane">3: Offlane</option>
<option value="4:support">4: Support</option>
<option value="5:support">5: Support</option>
</select>
</td>
</tr>
<tr>
<td>Team</td>
<td><input type="text" name="team[team_3]" size="40">
</td>
</tr>
<tr>
<td>Game</td>
<td><select name="game[game_3]">
<option value="dota2">Dota 2</option>
<option value="leagueoflegends">League of Legends</option>
<option value="starcraft2">StarCraft 2: Heart of the Swarm</option>
<option value="USFIV">USFIV</option>
</select>
</td>
</tr>
<!-- Player 4 -->
<td></td>
<td><b>Player 4</b></td>
</tr>
<tr>
<td>Steam ID</td>
<td><input type="text" name="playerid[player_4]" size="20">
</td>
</tr>
<tr>
<td>Fisrt Name</td>
<td><input type="text" name="firstname[firstname_4]" size="20">
</td>
</tr>
<tr>
<td>last Name</td>
<td><input type="text" name="lastname[lastname_4]" size="20">
</td>
</tr>
<tr>
<td>Position</td>
<td><select name="position[position_4]">
<option value="1:hardcarry">1: Hard Carry</option>
<option value="2:mid">2: Mid</option>
<option value="3:offlane">3: Offlane</option>
<option value="4:support">4: Support</option>
<option value="5:support">5: Support</option>
</select>
</td>
</tr>
<tr>
<td>Team</td>
<td><input type="text" name="team[team_4]" size="40">
</td>
</tr>
<tr>
<td>Game</td>
<td><select name="game[game_4]">
<option value="dota2">Dota 2</option>
<option value="leagueoflegends">League of Legends</option>
<option value="starcraft2">StarCraft 2: Heart of the Swarm</option>
<option value="USFIV">USFIV</option>
</select>
</td>
</tr>
<!-- Player 5 -->
<td></td>
<td><b>Player 5</b></td>
</tr>
<tr>
<td>Steam ID</td>
<td><input type="text" name="playerid[player_5]" size="20">
</td>
</tr>
<tr>
<td>Fisrt Name</td>
<td><input type="text" name="firstname[firstname_5]" size="20">
</td>
</tr>
<tr>
<td>last Name</td>
<td><input type="text" name="lastname[lastname_5]" size="20">
</td>
</tr>
<tr>
<td>Position</td>
<td><select name="position[position_5]">
<option value="1:hardcarry">1: Hard Carry</option>
<option value="2:mid">2: Mid</option>
<option value="3:offlane">3: Offlane</option>
<option value="4:support">4: Support</option>
<option value="5:support">5: Support</option>
</select>
</td>
</tr>
<tr>
<td>Team</td>
<td><input type="text" name="team[team_5]" size="40">
</td>
</tr>
<tr>
<td>Game</td>
<td><select name="game[game_5]">
<option value="dota2">Dota 2</option>
<option value="leagueoflegends">League of Legends</option>
<option value="starcraft2">StarCraft 2: Heart of the Swarm</option>
<option value="USFIV">USFIV</option>
</select>
</td>
</tr>
<!-- Player Sub 1 [6] -->
<td></td>
<td><b>Sub 1 (Optional)</b></td>
</tr>
<tr>
<td>Steam ID</td>
<td><input type="text" name="playerid[player_6]" size="20">
</td>
</tr>
<tr>
<td>Fisrt Name</td>
<td><input type="text" name="firstname[firstname_6]" size="20">
</td>
</tr>
<tr>
<td>last Name</td>
<td><input type="text" name="lastname[lastname_6]" size="20">
</td>
</tr>
<tr>
<td>Position</td>
<td><select name="position[position_6]">
<option value="1:hardcarry">1: Hard Carry</option>
<option value="2:mid">2: Mid</option>
<option value="3:offlane">3: Offlane</option>
<option value="4:support">4: Support</option>
<option value="5:support">5: Support</option>
</select>
</td>
</tr>
<tr>
<td>Team</td>
<td><input type="text" name="team[team_6]" size="40">
</td>
</tr>
<tr>
<td>Game</td>
<td><select name="game[game_6]">
<option value="dota2">Dota 2</option>
<option value="leagueoflegends">League of Legends</option>
<option value="starcraft2">StarCraft 2: Heart of the Swarm</option>
<option value="USFIV">USFIV</option>
</select>
</td>
</tr>
<!-- Player Sub 2 [7] -->
<td></td>
<td><b>Sub 2</b></td>
</tr>
<tr>
<td>Steam ID</td>
<td><input type="text" name="playerid[player_7]" size="20">
</td>
</tr>
<tr>
<td>Fisrt Name</td>
<td><input type="text" name="firstname[firstname_7]" size="20">
</td>
</tr>
<tr>
<td>last Name</td>
<td><input type="text" name="lastname[lastname_7]" size="20">
</td>
</tr>
<tr>
<td>Position</td>
<td><select name="position[position_7]">
<option value="1:hardcarry">1: Hard Carry</option>
<option value="2:mid">2: Mid</option>
<option value="3:offlane">3: Offlane</option>
<option value="4:support">4: Support</option>
<option value="5:support">5: Support</option>
</select>
</td>
</tr>
<tr>
<td>Team</td>
<td><input type="text" name="team[team_7]" size="40">
</td>
</tr>
<tr>
<td>Game</td>
<td><select name="game[game_7]">
<option value="dota2">Dota 2</option>
<option value="leagueoflegends">League of Legends</option>
<option value="starcraft2">StarCraft 2: Heart of the Swarm</option>
<option value="USFIV">USFIV</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td align="right"><input type="submit" name="submit" value="Sent"></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
and then the PHP code
<?php
/*
Plugin Name: FSdota
Description: submit form data into sql database
Author: F. May
Version: 1.0
*/
//inserting data order
$con=mysqli_connect("xxxxxxxx","xxxxxxx","xxxxxx!","xxxxx");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
//define values
$player_a = array($playerid_1,$playerid_2,$playerid_3,$playerid_4,$playerid_5,$playerid_6,$playerid_7);
$firstname_a = array($firstname_1,$firstname_2,$firstname_3,$firstname_4,$firstname_5,$firstname_6,$firstname_7);
$lastname_a = array($lastnanme_1,$lastnanme_2,$lastnanme_3,$lastnanme_4,$lastnanme_5,$lastnanme_6,$lastnanme_7);
$position_a = array($position_1,$position_2,$position_3,$position_4,$position_5,$position_6,$position_7);
$team_a = array($team_1,$team_2,$team_3,$team_4,$team_5,$team_6,$team_7);
$game_a = array($game_1,$game_2,$game_3,$game_4,$game_5,$game_6,$game_7);
$playerid = mysqli_real_escape_string($con, '$playerid_a');
$firstname = mysqli_real_escape_string($con, '$firstname_a');
$lastname = mysqli_real_escape_string($con, '$lastname_a');
$position = mysqli_real_escape_string($con,'$position_a');
$team = mysqli_real_escape_string($con, '$team_a');
$game = mysqli_real_escape_string($con, '$game_a');
for ($i = 1; $i < 7; $i++) {
//define arrays into variables with counter
// $a = $playerid_a[$];
// $b = $firstname_a[$i];
// $c = $lastname_a[$i];
// $d = $position_a[$i];
// $e = $team_a[$i];
// $f = $game_a[$i];
$str[ ] = "('{$player_[$i]}','{$firstname_[$i]}','{$lastname_[$i]}','{$position_[$i]}','{$team_[$i]}','{$game_[$i]}')";
}
$s= implode(',', $str);
$sql="INSERT INTO wp_es_fstest (playerid, firstname, lastname, position, team, game) VALUES $s";
echo $sql;
mysqli_close($con);
?>
I dont think I have defined everything correctly, in the echo i am null values.
INSERT INTO wp_es_fstest (playerid, firstname, lastname, position, team, game) VALUES ('','','','','',''),('','','','','',''),('','','','','',''),('','','','','',''),('','','','','',''), ('','','','','','')
Trying to pass the value from Drop down list through but couldnt get it.
<tr>
<td>Size <br>
(Only applicable for T-Shirt):</td>
<td><select name=size>
<option value=N>NIL</option>
<option value=S>S</option>
<option value=M>M</option>
<option value=L>L</option>
<option value=XL>XL</option>
</select></td>
</tr>
<tr>
<td></td>
<td><a href= manageProduct.php?size=$_GET[size]>Insert</a></td>
</tr>
Give this a try: (just an example).
<form action="<?php $_SERVER['PHP_SELF']?>" method="GET">
<table>
<tr>
<td nowrap>Size:
(Only applicable for T-Shirt):</td>
<td><select name="size">
<option value="N">NIL</option>
<option value="S">S</option>
<option value="M">M</option>
<option value="L">L</option>
<option value="XL">XL</option>
</select></td>
</tr>
<tr>
<td><p align="right"></p></td>
<td><input type="submit" value="Insert" />
</td>
</tr>
</table>
</form>
<?php
$size = $_GET['size'];
if($_GET['size']=="N")
{
echo "you chose NOTHING, make another choice.";
}
else {
echo "Your choice of size is: $size";
}
?>
Html
<form action="manageProduct.php" method="POST">
<table>
<tr>
<td>Size <br>
(Only applicable for T-Shirt):</td>
<td><select name=size>
<option value=N>NIL</option>
<option value=S>S</option>
<option value=M>M</option>
<option value=L>L</option>
<option value=XL>XL</option>
</select></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Insert" /></td>
</tr>
</table>
</form>
PHP
$size = $_POST['size'];
You need a form using the GET action then you can get your variable.
Assuming this page is the manageProduct.php:
<!--GET your data from the submitted form OR do something depending on what size returns in the url-->
<?php
if($_GET['size']=="SIZE"){ echo whatever or do whatever}
?>
<td>Whatever you're trying to do</td>
<form id="form" method="get" action="manageProduct.php">
<tr>
<td>Size <br>
(Only applicable for T-Shirt):</td>
<td><select name="size">
<option value="N">NIL</option>
<option value="S">S</option>
<option value="M">M</option>
<option value="L">L</option>
<option value="XL">XL</option>
</select></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Insert" /></td>
<br />
</form>
</tr>
The very first field named Forte ID posts a value of 0 no matter what selection I choose. Here are my two files:
Index.php(Form)
</head>
<h1> Customer Service Log Form </h1>
<form method="post" action="insert.php">
<table width="625" border="0">
<tr>
<td> Forte ID:</td>
<td><select id="ForteID" name="ForteID">
<option value="0">Select Your ID</option>
<option value="as7326">as7326</option>
<option value="aw8743">aw8743</option>
<option value="bj0920">bj0920</option>
<option value="bs1441">bs1441</option>
<option value="dk7017">dk7017</option>
<option value="dl7686">dl7686</option>
<option value="dm2940">dm2940</option>
<option value="jn2468">jn2468</option>
<option value="jw9598">jw9598</option>
<option value="kp4945">kp4945</option>
<option value="nl2589">nl2589</option>
<option value="rp7021">rp7021</option>
<option value="sh1346">sh1346</option>
</select></td>
</tr>
<tr>
<td> Disposition</td>
<td><select id="disposition" name="disposition">
<option value="0">Select a Disposition</option>
<option value="Save">Save</option>
<option value="Sale">Sale</option>
<option value="LOC">LOC</option>
<option value="Backout">Backout</option>
<option value="Revision">Revision</option>
<option value="Revision">Revision/Save</option>
</select>
</td>
</tr>
</table>
<hr />
<br />
<table width="400" border="0">
<tr>
<td>App Number:</td>
<td></td>
<td><input name="appnumber" type="text" required="required"></td>
</tr>
<tr>
<td>Finance Number:</td>
<td></td>
<td><input type="text" name = "Finance_Num"></td>
</tr>
<tr>
<td>Phone Number:</td>
<td></td>
<td><input type="text" name = "Phone_Num"></td>
</tr>
<tr>
<td># of Payments Collected:</td>
<td></td>
<td><input type="text" name = "num_payments"></td>
</tr>
<tr>
<td>ACH/CC</td>
<td></td>
<td><select id="ForteID" name="ForteID">
<option value="0">Select Payment</option>
<option value="ach">Checking</option>
<option value="cc">Credit Card</option>
</select></td>
</tr>
<tr>
<td>Date:</td>
<td></td>
<td><input name = "date" type="text" id="datepicker" autocomplete="off" required="required"></td>
</tr>
</table>
<br />
Notes:
<br />
<textarea name="notes" id="notes" cols="45" rows="5"></textarea>
</fieldset>
<hr />
<input type="Submit" name="formSubmit" value="Submit">
<input type="Reset" name="formReset" value="Reset">
<input type="button" value="View Logs" onClick="window.location.href='logs.php';">
</form>
</head>
Insert.php (PHP file to insert data from form into SQL Server Database):
$serverName = 'Server\SQLEXPRESS';
$connectionInfo = array('Database'=>'database', 'UID'=>'username', 'PWD'=>'password');
$connection = sqlsrv_connect($serverName, $connectionInfo);
if( $connection === false )
{
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
}
$tsql = "INSERT INTO logs(ForteID, disposition, appnumber, Finance_Num, num_payments, ach_cc, date, notes, Phone_Num) VALUES (?,?,?,?,?,?,?,?,?)";
$parameters = array( $_POST[ForteID], $_POST[disposition], $_POST[appnumber], $_POST[Finance_Num], $_POST[num_payments], $_POST[ach_cc], $_POST[date], $_POST[notes], $_POST[Phone_Num]);
$stmt = sqlsrv_query($connection, $tsql, $parameters);
if( $stmt === false ){
echo "Statement could not be executed.\n";
die( print_r( sqlsrv_errors(), true));
} else {
echo "Rows affected: ".sqlsrv_rows_affected( $stmt )."\n";
}
No matter what option is selected in the index.php field Forte ID, it posts a value of 0. What is wrong. It was working before I added a field named Phone Number. But doesnt make sense why that would screw up the selections.
Let me know if I need to clarify anything and thanks for the help in advance!
You have to fields called ForteID
<select id="ForteID" name="ForteID">
<option value="0">Select Payment</option>
<option value="ach">Checking</option>
<option value="cc">Credit Card</option>
is the 2nd one
My below code is posting at both times when the checkbox is checked or not checked. When its not checked I am getting alert and then posting. But when checked its posting automatically.
I need JavaScript to post the form when Submit button is clicked and checkbox should be kept checked. Else it should just provide me an alert. But unfortunately the page is reloading even when keeping the checkbox unchecked and using submit button.
My code is
<script type="text/javascript">
function check()
{
if(document.getElementById("privacy").checked == true)
{
document.print.submit();
}
else{
alert('Please read and accept our privacy statments to proceed.');
};
}
</script>
</head>
<body>
<form id="print" action="printfile.php">
<div id="express">
<table width="800">
<tr>
<td colspan="2"><span style="color:#FF0000; font-size:26px;">Express Application</span></td>
</tr>
<tr>
<td width="300"> </td>
<td width="500"> </td>
</tr>
<tr>
<td>First Name (Required) </td>
<td><input name="firstname" type="text" size="30"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Last Name </td>
<td><input name="lastname" type="text" size="30"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Email (Required) </td>
<td><input name="email" type="text" id="email" size="30"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Purpose of finance (Required) </td>
<td><select name="purpose" id="purpose">
<option selected="selected">Home Loan</option>
<option>Refinance</option>
<option>Investment Loan</option>
<option>Debit Consolidation</option>
<option>Others</option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Your deposit amount </td>
<td><input name="depositamount" type="text" size="30"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Amount you need to borrow? </td>
<td><input name="borrowamount" type="text" size="30"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Brief description of purpose of <br />
finance (Required) <br />
<br />
<br />
<br />
<br />
<br /></td>
<td><textarea name="purposedesc" cols="60" rows="10" id="purposedesc"></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Application Type<br />
<br /></td>
<td><label>
<input type="radio" name="apptype" value="Single" onclick="document.getElementById('singleapp').style.visibility = 'visible'; document.getElementById('jointapp').style.visibility = 'hidden';" />
Single Application</label>
<br />
<label>
<input type="radio" name="apptype" value="Joint" onclick="document.getElementById('singleapp').style.visibility = 'visible'; document.getElementById('jointapp').style.visibility = 'visible';" />
Joint Application</label></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2"><input name="privacy" type="checkbox" id="privacy" value="checkbox" />
Privacy Act (Required) <br />
<br />
I have read the Privacy Act 1988 (as Amended) and understand that by selecting the submit button I/we authorise Best Aussie Broker to act on my/our behalf and manage personal information in relation to this application. </td>
</tr>
</table>
<br />
Last step then we will get all listed Australian vendors to fight it out for your best deal.<br />
<br />
<table width="800" border="0" style="">
<tr>
<td width="400">
<div id="singleapp">
<table width="400" border="0">
<tr>
<td colspan="2" bgcolor="#333300"><span class="style1">Your application </span></td>
</tr>
<tr>
<td width="150"> </td>
<td width="240"> </td>
</tr>
<tr>
<td>Date of Birth</td>
<td><select name="day1" id="day1">
<option selected="selected">1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
<select name="month1" id="month1">
<option selected="selected">Jan</option>
<option>Feb</option>
<option>Mar</option>
<option>Apl</option>
<option>May</option>
<option>Jun</option>
<option>Jul</option>
<option>Aug</option>
<option>Sep</option>
<option>Oct</option>
<option>Nov</option>
<option>Dec</option>
</select>
<input name="year1" type="text" id="year1" style="padding:1.2px;" size="8" maxlength="4" /> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Address</td>
<td><input name="address1" type="text" id="address1" size="20"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Suburb</td>
<td><input name="suburb1" type="text" id="suburb1" size="20"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>PostCode</td>
<td><input name="postcode1" type="text" id="postcode1" size="20"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>State</td>
<td><select name="state1" id="state1">
<option value="Victoria" selected="selected">VIC</option>
<option value="New South Wales">NSW</option>
<option value="QueensLand">QLD</option>
<option value="South Australia">SA</option>
<option value="Western Australia">WA</option>
<option value="Tasmania">TAS</option>
<option value="New Zeland">NZ</option>
<option value="Other">Other</option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Best contact </td>
<td><select name="phone1" id="phone1">
<option>Phone</option>
<option>Email</option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Phone number </td>
<td><input name="number1" type="text" id="number1" size="20"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Marital status </td>
<td><select name="maried1" id="maried1">
<option>Single</option>
<option>Married</option>
<option>Other</option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Residential status </td>
<td><select name="rstatus1" id="rstatus1">
<option selected="selected">Renting</option>
<option>Home Owner</option>
<option>Home Mortgaged</option>
<option>Board</option>
<option>Other</option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Children/dependents</td>
<td><select name="childs1" id="childs1">
<option value="0" selected="selected">0</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 or more">6 or more</option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Net income </td>
<td><input name="netincome1" type="text" id="netincome1" size="10"/>
per
<select name="months1" id="months1">
<option>Month</option>
<option>Year</option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Current employer </td>
<td><input name="cemployer1" type="text" id="cemployer1" size="20"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Time at this<br />
employer </td>
<td> Years
<select name="years1" id="years1">
<option value="1" selected="selected">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="More">More</option>
</select>
Months
<select name="emonth1" id="emonth1">
<option value="0" selected="selected">0</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>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input name="submit" type="submit" value="Submit my Application" onclick="check();" /></td>
</tr>
</table>
</div>
</td>
<td width="400">
<div id="jointapp">
<table width="400" border="0">
<tr>
<td colspan="2" bgcolor="#333300"><span class="style1">Your partner's application </span></td>
</tr>
<tr>
<td width="150"> </td>
<td width="240"> </td>
</tr>
<tr>
<td>Date of Birth</td>
<td><select name="day11" id="day11">
<option selected="selected">1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
<select name="month11" id="month11">
<option selected="selected">Jan</option>
<option>Feb</option>
<option>Mar</option>
<option>Apl</option>
<option>May</option>
<option>Jun</option>
<option>Jul</option>
<option>Aug</option>
<option>Sep</option>
<option>Oct</option>
<option>Nov</option>
<option>Dec</option>
</select>
<input name="year2" type="text" size="8" maxlength="4" style="padding:1.2px;" /> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Address</td>
<td><input name="address12" type="text" id="address12" size="20"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Suburb</td>
<td><input name="suburb12" type="text" id="suburb12" size="20"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>PostCode</td>
<td><input name="postcode12" type="text" id="postcode12" size="20"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>State</td>
<td><select name="state12" id="state12">
<option value="Victoria" selected="selected">VIC</option>
<option value="New South Wales">NSW</option>
<option value="QueensLand">QLD</option>
<option value="South Australia">SA</option>
<option value="Western Australia">WA</option>
<option value="Tasmania">TAS</option>
<option value="New Zeland">NZ</option>
<option value="Other">Other</option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Best contact </td>
<td><select name="phone11" id="phone11">
<option>Phone</option>
<option>Email</option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Phone number </td>
<td><input name="number11" type="text" id="number11" size="20"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Marital status </td>
<td><select name="married12" id="married12">
<option>Single</option>
<option>Married</option>
<option>Other</option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Residential status </td>
<td><select name="rstatus12" id="rstatus12">
<option selected="selected">Renting</option>
<option>Home Owner</option>
<option>Home Mortgaged</option>
<option>Board</option>
<option>Other</option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Children/dependents</td>
<td><select name="childs12" id="childs12">
<option value="0" selected="selected">0</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 or more">6 or more</option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Net income </td>
<td><input name="netincome12" type="text" id="netincome12" size="10"/>
per
<select name="months12" id="months12">
<option>Month</option>
<option>Year</option>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Current employer </td>
<td><input name="cemployer12" type="text" id="cemployer12" size="20"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Time at this<br />
employer </td>
<td> Years
<select name="years12" id="years12">
<option value="1" selected="selected">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="More">More</option>
</select>
Months
<select name="emonths12" id="emonths12">
<option value="0" selected="selected">0</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>
</select></td>
</tr>
</table>
<br />
<br />
<br />
<br />
<br />
</div>
</td>
</tr>
</table>
<p><br />
<br />
<center>
</center>
<br />
</p>
</div>
</form>
With the inline event handler syntax you're using it is easiest to return false so the default action (the submitting) isn't executed:
<input name="submit"
type="submit"
value="Submit my Application"
onclick="check(); return false;" />
You need to make the submit return false, otherwise it will just do the regular thing a form does when you click submit.
if(document.getElementById("privacy").checked == true)
{
document.print.submit();
}
else
{
alert('Please read and accept our privacy statments to proceed.');
return false;
}
Technically as it will be submitting anyway. You could just get it to check and only intercept if it is not checked.
if(document.getElementById("privacy").checked == false)
{
alert('Please read and accept our privacy statments to proceed.');
return false;
}
Also add return to the submit onclick (link #AndreKR said)
<input name="submit" type="submit" value="Submit my Application" onclick="return check();" />
I have to use same checkboxes and dropdowns according to the if condition ,---->
<div id="5" <? if($long_term_rental!=1) {?> style="display:none" <? } else {?>style="display:block" <? } ?>>
<table width="85%" >
<tr class="td3">
<td>City </td>
<td><select style="width:100px;" name="citylong" size="1" class="textfeild1" id="citylong">
<option <? if($citylong=="None")echo "selected='selected'";?>>None</option>
<option <? if($citylong=="Palm Springs")echo "selected='selected'";?>>Palm Springs</option>
<option <? if($citylong=="Cathedral City")echo "selected='selected'";?>>Cathedral City</option>
<option <? if($citylong=="Rancho Mirage")echo "selected='selected'";?>>Rancho Mirage</option>
<option <? if($citylong=="Palm Desert")echo "selected='selected'";?>>Palm Desert</option>
<option <? if($citylong=="La Quinta")echo "selected='selected'";?>>La Quinta</option>
<option <? if($citylong=="Indian Wells")echo "selected='selected'";?>>Indian Wells</option>
</select></td></tr>
<tr class="td2">
<td align="left">Upper/Lower/Town House/Single Story</td>
<td align="left"><select style="width:100px;" name="floorlong" size="1" class="textfeild1" id="floorlong">
<option <? if($floorlong=="None")echo "selected='selected'";?>>None</option>
<option <? if($floorlong=="Upper")echo "selected='selected'";?>>Upper</option>
<option <? if($floorlong=="Lower")echo "selected='selected'";?>>Lower</option>
<option <? if($floorlong=="TH")echo "selected='selected'";?>>TH</option>
<option <? if($floorlong=="Single Story")echo "selected='selected'";?>>Single Story</option>
</select></td>
</tr>
<tr class="td2">
<td> </td>
<td >Pets Allowed : </td>
<td ><input class="textfeild1" type="checkbox" name="petslong" id="petslong" value="Pets" <? if($petslong==1) echo "checked='checked'";?>/></td>
<td>Pool : </td>
<td><input class="textfeild1" type="checkbox" name="poollong" id="poollong" value="Pool" <? if($poollong==1) echo "checked='checked'";?>/></td>
<td align="right"> </td>
</tr>
<tr class="td2">
<td> </td>
<td>Jacuzzi : </td>
<td><input class="textfeild1" type="checkbox" name="jacuzzilong" id="jacuzzilong" value="Jacuzzi" <? if($jacuzzilong==1) echo "checked='checked'";?>/></td></div>
And on condition false display the below code---->
<div id="mylng" <? if($long_term_rental!=1) {?> style="display:block" <? } else {?>style="display:none" <? } ?>>
<table width="100%" >
<tr class="td3">
<td> </td>
<td>City </td>
<td><select style="width:100px;" name="city" size="1" class="textfeild1" id="city">
<option <? if($city=="None")echo "selected='selected'";?>>None</option>
<option <? if($city=="Palm Springs")echo "selected='selected'";?>>Palm Springs</option>
<option <? if($city=="Cathedral City")echo "selected='selected'";?>>Cathedral City</option>
<option <? if($city=="Rancho Mirage")echo "selected='selected'";?>>Rancho Mirage</option>
<option <? if($city=="Palm Desert")echo "selected='selected'";?>>Palm Desert</option>
<option <? if($city=="La Quinta")echo "selected='selected'";?>>La Quinta</option>
<option <? if($city=="Indian Wells")echo "selected='selected'";?>>Indian Wells</option>
</select></td>
<td align="right" style="width: 223px;">Upper/Lower/Town House/Single Story</td>
<td align="left"><select style="width:100px;" name="floor" size="1" class="textfeild1" id="floor">
<option <? if($floor=="None")echo "selected='selected'";?>>None</option>
<option <? if($floor=="Upper")echo "selected='selected'";?>>Upper</option>
<option <? if($floor=="Lower")echo "selected='selected'";?>>Lower</option>
<option <? if($floor=="TH")echo "selected='selected'";?>>TH</option>
<option <? if($floor=="Single Story")echo "selected='selected'";?>>Single Story</option>
</select></td></tr>
<tr class="td3">
<td> </td>
<td >Pets Allowed : </td>
<td ><input class="textfeild1" type="checkbox" name="pets" id="checkbox9" value="Pets" <? if($pets==1) echo "checked='checked'";?>/></td>
<td>Pool : </td>
<td><input class="textfeild1" type="checkbox" name="pool" id="checkbox8" value="Pool" <? if($pool==1) echo "checked='checked'";?>/></td>
<td align="right"> </td>
</tr>
<tr class="td3">
<td> </td>
<td>Jacuzzi : </td>
<td><input class="textfeild1" type="checkbox" name="jacuzzi" id="checkbox6" value="Jacuzzi" <? if($jacuzzi==1) echo "checked='checked'";?>/></td>
<td> </td>
<td> </td>
</tr>
</table></div>
But the code under <div id="5" is NOT WORKINg and the same code under <div id="mylng" is working PERFECTLY
Please help
at first you did not closed your
/tr
/table
at the end of
div id=5
please send us code with your form tag maybe your fault its on you HTML