Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help putting these states in the drop down list instead of showing up lik

ID: 3712554 • Letter: I

Question

I need help putting these states in the drop down list instead of showing up like this.

Here is my code;

<!DOCTYPE html>

<html lang="en">

<head>

<title>Lab 7, Part 1 and 2</title>

<meta charset="utf-8"/>

<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />

</head>

<body>

<h1>Tool Invoice Form</h1>

<form name="myForm" action="/formtest.php"

onsubmit="return validateForm()">

<label>First Name:

<input type="text" id="fname" name="firstName" size="30"/>

</label>

<br>

<br>

<label>Last Name:

<input type="text" id="lname" name="lastName" size="30"/>

</label>

<br>

<br>

<label> Street Address:

<input type="text" id="streetAdr" name="streetAddress" size="45"/>

</label>

<br>

<br>

<label>City:

<input type="text" id="city" name="City" size="30"/>

</label>

<br>

<br>

<label>State:

<select name="state">

<label> State:<select name="State">

<?php

$db=mysqli_connect(null,null,null,'weblab')

or die("Can't connect to DB:" . mysqli_connect_error());

$q ="SELECT state_abbr, state_name from state_t ORDER BY state_name";

$dbResult = mysqli_query($db,$q)

or die("Database query error" . mysqli_error($db));

$num = mysqli_num_rows($dbResult);

if ($num == 0) {

echo '<tr><td colspan="2">';

echo 'Database query retrieved zero rows.</td></tr>';

}

$statesList = "SELECT state_abbr, state_name FROM state_t ORDER BY state$

$result = $db->query($statesList);

$State_Dropdown = "";

$State_Dropdown = "<select>";

$State_Dropdown = "<option value = ''>Select State </option>";

if ($result->num_rows > 0) {

while($row = $result->fetch_assoc()) {

$stateAbbr = $row["state_abbr"];

$stateName = $row["state_name"];

$State_Dropdown .= "<option value = '$stateAbbr'>".$stateName."</opt$

}

$State_Dropdown .= "</select>";

} else {

echo "No States Found";

}

$db->close();

echo $State_Dropdown;

?>

</label>

<table>

<tr>

<th>Product Name</th>

<th>Price</th>

<th>Weight(lb.)</th>

<th>Quantity</th>

</tr>

<tr>

<td>Pliers</td>

<td id="Plier_td">$15.00</td>

<td>2.5</td>

<td>

<input type="text" id="plyr" name="pliers" size="2"/>

</td>

</tr>

<tr>

<td>Chisels</td>

<td id="Chisel_td">$20.00</td>

<td>3</td>

<td>

<input type="text" id="chsl" name="chisel" size="2"/>

</td>

</tr>

<tr>

<td>Hoes</td>

<td id="Hoe_td">$30.00</td>

<td>4.3</td>

<td>

<input type="text" id="hoe" name="hoe" size="2"/>

</td>

</tr>

</table>

<h2>Payment Method:</h2>

<label>

<input type="radio" name="payment" id="visa" value="visa"/>

Visa

</label>

<br>

<label>

<input type="radio" name="payment" id="master" value="master"/>

Master Card

</label>

<br>

<label>

<input type="radio" name="payment" id="discover" value="discover"/>

Discover

</label>

<br>

<label>

<input type="radio" name="payment" id="amex" value="american express"/>

American Express

</label>

<br>

<p>

<input type="submit" value="Submit Order"/>

<input type="reset" value="Clear Order Form"/>

</p>

</form>

<script type="text/javascript">

function validateForm()

{

var pliers_price=document.getElementById("Plier_td").innerText;

var chisels_price=document.getElementById("Chisel_td").innerText;

var hoes_price=document.getElementById("Hoe_td").innerText;

var plier_qty=document.getElementById("plyr").value;

var chisel_qty=document.getElementById("chsl").value;

var hoe_qty=document.getElementById("hoe").value;

var reg = /^d*$/;

var flag = true;

flag = reg.test(plier_qty) && reg.test(chisel_qty) && reg.test(hoe_qty);

if(!flag)

window.alert('Non numeric Quantity found!');

return flag;

}

</script>

Tool Invoice Form First Name: Last Name: Street Address: State: Select State Alabama American Samoa District of Columbia Florida Guam Kentucky Lousiana Maine Maryland Massachusetts

Explanation / Answer

Following is the answer:

<!DOCTYPE html>

<html lang="en">

<head>

<title>Lab 7, Part 1 and 2</title>

<meta charset="utf-8"/>

<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />

</head>

<body>

<h1>Tool Invoice Form</h1>

<form name="myForm" action="/formtest.php"

onsubmit="return validateForm()">

<label>First Name:

<input type="text" id="fname" name="firstName" size="30"/>

</label>

<br>

<br>

<label>Last Name:

<input type="text" id="lname" name="lastName" size="30"/>

</label>

<br>

<br>

<label> Street Address:

<input type="text" id="streetAdr" name="streetAddress" size="45"/>

</label>

<br>

<br>

<label>City:

<input type="text" id="city" name="City" size="30"/>

</label>

<br>

<br>

<label>State:

<select name="state">

<label> State:<select name="State">

<?php

$db=mysqli_connect(null,null,null,'weblab')

or die("Can't connect to DB:" . mysqli_connect_error());

$q ="SELECT state_abbr, state_name from state_t ORDER BY state_name";

$dbResult = mysqli_query($db,$q)

or die("Database query error" . mysqli_error($db));

$num = mysqli_num_rows($dbResult);

if ($num == 0) {

echo '<tr><td colspan="2">';

echo 'Database query retrieved zero rows.</td></tr>';

}

$statesList = "SELECT state_abbr, state_name FROM state_t ORDER BY state";

$result = $db->query($statesList);

?>

<select name="state">

<option>--Select select--</option>

<?php

if ($result->num_rows > 0) {

while($row = $result->fetch_assoc()) {

$stateAbbr = $row["state_abbr"];

$stateName = $row["state_name"];

?>

<option value="<?php echo $stateAbbr ?>"><?php echo $stateName; ?></option>

<?php

}

} else {

echo "No States Found";

}

?>

</select>

<?php

$db->close();

echo $State_Dropdown;

?>

</label>

<table>

<tr>

<th>Product Name</th>

<th>Price</th>

<th>Weight(lb.)</th>

<th>Quantity</th>

</tr>

<tr>

<td>Pliers</td>

<td id="Plier_td">$15.00</td>

<td>2.5</td>

<td>

<input type="text" id="plyr" name="pliers" size="2"/>

</td>

</tr>

<tr>

<td>Chisels</td>

<td id="Chisel_td">$20.00</td>

<td>3</td>

<td>

<input type="text" id="chsl" name="chisel" size="2"/>

</td>

</tr>

<tr>

<td>Hoes</td>

<td id="Hoe_td">$30.00</td>

<td>4.3</td>

<td>

<input type="text" id="hoe" name="hoe" size="2"/>

</td>

</tr>

</table>

<h2>Payment Method:</h2>

<label>

<input type="radio" name="payment" id="visa" value="visa"/>

Visa

</label>

<br>

<label>

<input type="radio" name="payment" id="master" value="master"/>

Master Card

</label>

<br>

<label>

<input type="radio" name="payment" id="discover" value="discover"/>

Discover

</label>

<br>

<label>

<input type="radio" name="payment" id="amex" value="american express"/>

American Express

</label>

<br>

<p>

<input type="submit" value="Submit Order"/>

<input type="reset" value="Clear Order Form"/>

</p>

</form>

<script type="text/javascript">

function validateForm()

{

var pliers_price=document.getElementById("Plier_td").innerText;

var chisels_price=document.getElementById("Chisel_td").innerText;

var hoes_price=document.getElementById("Hoe_td").innerText;

var plier_qty=document.getElementById("plyr").value;

var chisel_qty=document.getElementById("chsl").value;

var hoe_qty=document.getElementById("hoe").value;

var reg = /^d*$/;

var flag = true;

flag = reg.test(plier_qty) && reg.test(chisel_qty) && reg.test(hoe_qty);

if(!flag)

window.alert('Non numeric Quantity found!');

return flag;

}

</script>

</body>

</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote