<form id="promacform" onsubmit="return protein_calculator(this);" method="post">
Weight: <input type="text" name="protein_weight" id="protein_weight" size="5"; /> lbs.<br />
Activity level (1.1-1.4): <input type="text" name="protein_activity" id="protein_activity" size="5"; /> <br />
<br><input type="submit" name="submit" id="submit" value="Calculate" /><br />
<div id="protein_result"></div>
</form>
Im trying to add a drop down menu for the activity level which will have 4 options:
Lightly active (moderate exercise but sedentary job)
Moderately active (intense exercise but sedentary job)
Very active (moderate exercise and active job)
Extra active (intense exercise and active job)
im not quite sure how to set it up, because the way it is set up now the user has to input a number ranging from 1.1-1.4(activity level range) and from there it calculates it.
From my comment, you presumably want just this:
<label>Activity level
<select name="protein_activity">
<option value="1.1">Lightly Active</option>
<option value="1.2">Moderately Active</option>
<option value="1.3">Very Active</option>
<option value="1.4">Extra Active</option>
</select>
</label>
Another possibility you may be interested is a range slider, but you would have to modify your PHP side to accommodate that the form would send from 1-4 instead of 1.1-1.4 but it might add a user experience. This is just a quick and dirty example of a range. Note range is only available in HTML5:
<style>
input[type=range] {
width: 300px;
}
ul.ranger {
width: 300px;
display: table;
list-style: none;
margin: 0;
padding: 0;
}
ul.ranger li {
display: table-cell;
text-align: center;
width: 75px;
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
padding: 0;
}
ul.ranger li:last-child {
text-align: right;
}
ul.ranger li:first-child {
text-align: left;
}
</style>
<form>
<input type="range" min="1" max="4" value="2" id="slider" name="protein_activity">
<ul class="ranger">
<li>Light</li>
<li>Moderate</li>
<li>Heavy</li>
<li>Extreme</li>
</ul>
</form>
Related
I'm currently making a website using PHP, HTML and a classless CSS (Water.css) Right now, I have a problem aligning my search bars and buttons into a row
<!-- Search Bar Name-->
<form action="search.php" method="GET">
<input type="text" name="query" placeholder="Search Equipment">
<input type="submit" value="Go">
</form>
<!-- Search Bar Price-->
<form action="searchprice.php" method="post">
<label for="min_price">Minimum price:</label>
<input type="text" name="min_price" id="min_price">
<label for="max_price">Maximum price:</label>
<input type="text" name="max_price" id="max_price">
<input type="submit" name="submit" value="Search">
</form>
<button onclick="window.location='add_equipment.php'">Add Equipment</a></button>
The search bars and the button work perfectly fine, however I have no clue why it stacks up like a column instead of being in a row.
It would be nice if someone could help me with this, I am a newbie to HTML
Not sure if this is what you are looking for:
Like Amir said lots of information on using divs,flex,grid in css. I feel like the classless link is making your inputs do that everytime I link to it, it puts everything in columns.
<!DOCTYPE html>
<html>
<head>
<title>Equipments</title>
<meta charset="utf-8">
<link rel="stylesheet" a href="./css/main.css">
<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css#2/out/water.min.css"> -->
</head>
<body>
<div class="nav">
<h2>List Of Equipments</h2>
<div class="navs">
<!-- Search Bar Name-->
<form action="search.php" method="GET">
<label for="Search">Search Equipment</label>
<input type="text" name="query" placeholder="Search Equipment"><br>
<input id="Sbutton" type="submit" value="Go">
</form>
</div>
<!-- Search Bar Price-->
<div class="navs">
<form action="searchprice.php" method="post">
<label for="min_price">Minimum price:</label>
<input type="text" name="min_price" id="min_price"><br>
<label for="max_price">Maximum price:</label>
<input type="text" name="max_price" id="max_price"><br>
<input id="Sbutton2" type="submit" name="submit" value="Search">
<button id="Sbutton3" onclick="window.location='add_equipment.php'">Add Equipment</button>
</form>
</div>
</div>
</body>
</html>
Here is the CSS when I am styling I like to change background of each div class so I can get a visual of what is happening as I change code.
.nav{
display: flex;
flex-direction: column;
margin: 10px;
margin-left: 15%;
margin-right: 15%;
padding-bottom: 20px;
background-color: rgb(77, 76, 76);
}
h2{
text-align: center;
font-size: 24px;
font-weight:bolder;
}
.navs {
width: 50%;
background-color: rgb(108, 109, 109);
height: 150px;
text-align: center;
margin-left: 25%;
margin-top: 20px;
padding-top: 10px;
}
#Sbutton{
font-size: 16px;
height: 150%;
width: 15%;
margin-left: 15%;
margin-top: 10px;
}
#Sbutton2{
font-size: 16px;
height: 150%;
width: 15%;
margin-left: 15%;
margin-top: 10px;
}
#Sbutton3{
font-size: 16px;
height: 150%;
width: 25%;
margin-top: 10px;
}
table{
border:3px solid gray;
border-collapse: collapse;
}
th{
border: 2px solid gray;
padding: 6px;
}
td{
border: 2px solid gray;
text-align: center;
}
Hope this helps.
I have a number of checkboxes that return an array of data to PHP. They are all named 'Plans[]' but with different IDs.
I have a CSS checkbox styler that replaces the usual HTML checkbox with something more fancy...
When the page is displayed, there is one (or several) that are 'checked', but they don't display as checked (I think one does but that is hidden usually).
I am assuming that the problem is caused by them all having the same name and so somehow they are the checked attribute is not getting acted on for all of them for this reason.
I have tried wrapping each of them in their own forms (as I saw this suggested elsewhere) but to no avail.
Here's an example of what it looks like:
<style type="text/css">
.checkOpt input {
position: absolute;
opacity: 0;
cursor: pointer;
}
/* Create a custom radio button */
.checkmark {
position: absolute;
top: -.3em;
right: 5%;
height: 25px;
width: 25px;
background-color: #fff;
border-radius: 20%;
border: 1px;
border-color: #1e62d0;
border-style: dashed;
}
/* Create the indicator (the dot/circle - hidden when not checked) */
.checkmark:after {
font-weight: 900;
color: blue;
margin-top: -11px;
margin-left: -3px;
font-family: Arial, Helvetica, sans-serif;
font-size: 28px;
content: "\2714";
position: absolute;
display: none;
}
/* Style the indicator (dot/circle) */
.checkOpt .checkmark:after {
top: 8px;
left: 9px;
width: 8px;
height: 8px;
border-radius: 50%;
/* background: white; */
text-shadow: -1px -1px 0 #7f7f7f, 1px -1px 0 #7f7f7f, -1px 1px 0 #7f7f7f, 1px 1px 0 #7f7f7f;
}
/* Show the indicator (dot/circle) when checked */
.checkOpt input:checked~.checkmark:after {
display: block;
}
/* On mouse-over, add a grey background color */
.checkOpt:hover input ~ .checkmark {
background-color: #97c4fe;
}
/* When the radio button is checked, add a blue background */
.checkOpt input:checked ~ .checkmark {
background-color: #2196F3;
}
.checkOpt input:disabled ~ .checkmark {
background-color:#b0c7df; pointer:default;
}
.test {
position: relative;
height:60px;
}
</style>
<div class="test">
<div class="checkOpt" style="top:20px;">
<label class="labelopt">
<input type="checkbox" name="plans[]" class="checkb " title="Transfer existing line - OFNL" id="12" value="0.00" checked="checked" >
<span class="checkmark"></span>
</label>
</div>
</div>
<div class="test">
<div class="checkOpt" >
<label class="labelopt">
<input type="checkbox" name="plans[]" class="checkb " title="Paper Bill" id="35" value="2.00" >
<span class="checkmark"></span>
</label>
</div>
</div>
<div class="test">
<div class="checkOpt">
<label class="labelopt">
<input type="checkbox" name="plans[]" class="checkb " title="Transfer existing line " id="12" value="0.00" checked="checked" disabled="disabled">
<span class="checkmark"></span>
</label>
</div>
</div>
...only one of these (the first) is showing as checked - the rest are not.
Does anyone have any ideas what I might do to get round this (without coding changes to the subsequent data collection if possible!)
tried everything I can think of and would welcome any suggestions....
UPDATE - I tried updating the page so that the checkboxes have different names ('Plans[0]', 'Plans[1]' etc.) and the checkmarks suddenly started to appear in the right places.
The issue is now that there is (legacy) JQuery code that doesn't work, i.e.
$("input[name='plans[]']:checked").each(function(){
var thisPlan= $(this).attr('id'); var thisVal = $(this).attr('value');
plans.push(thisPlan);
planValues.push(thisVal);
// ....
// ....
}
I guess this would work if the Plans list were just POSTed and picked up by PHP, but in fact it is intercepted by Javascript, processed and re-posted via Ajax to the next (PHP) page (where it is picked up quite simply by $_POST['plans']). It's a real mess, but Ihave inherited it...
Anyone have any idea how I could work round this without breaking all the legacy (Javascript/JQuery) code?
SOLVED. I have discovered that there is actually a bit of Javascript/JQuery code that is overwriting the 'checked' attribute and this is causing the problem. The 'name' duplication was a red herring - by changing the names (from 'plans[]') I just stopped the code working (it used $('input[name="plans[]"]').each(function ()).
Thanks for your suggestions and help - Sorry to waste anyone's time. It's a bit of a nightmare trying to unravel someone else's mucky code!
Now I just have to get the functionality to work without that code...
The issue is that you're absolutely positioning them as Quentin stated in the comments. There are a few other issues:
You have two elements with the same ID and this isn't permitted (12)
IDs should start with a letter
Your first element has the attributed disabled = "" but this will make the item disabled irrespective of the value of the attribute. It's not ideal, I know.
disabled element values are usually not sent with the form (see link in the bullet point above) which may explain why it's not getting to your server script. this might be the cause as the check box is ticked but also disabled and the browser may be just ignoring all disabled checkboxes when sending the form data.
It's the same for checked = "", if the checked attribute is present on in you input element it'll still be checked.
I've had a go at what I think you're trying to achieve and marked up any changes.
.checkOpt {
/* added this so the container has some size */
height: fit-content;
display: inline-block;
}
.checkOpt input {
/* added this, you're looking to make your checkbox invisible so just use display:none */
display:none;
/* removed this
position: absolute;
opacity: 0;
cursor: pointer;
*/
}
/* Create a custom radio button */
.checkmark {
/* removed this
position: absolute;
top: 0em;
/*
right: 5%;*/
/* added this so that the tick marks are positioned in the middle so you don't have to use
absolute positioning on them */
display: inline-flex;
align-items:center;
justify-content:center;
height: 25px;
width: 25px;
background-color: #fff;
border-radius: 20%;
border: 1px;
border-color: #1e62d0;
border-style: dashed;
cursor:pointer;
}
.checkb:checked ~ .checkmark:after {
/*if the checkbox is checked then make the tick appear by making it opaque */
opacity:1;
}
/* Create the indicator (the dot/circle - hidden when not checked) */
.checkmark:after {
font-weight: 900;
/*color: white;
margin-top: -11px;
margin-left: -3px;*/
font-family: Arial, Helvetica, sans-serif;
font-size: 28px;
content: "\2714";
/* added this - makes the tick mark transparent when it's not checked */
opacity: 0;
/*position: absolute;*/
/*display: none;*/
}
.checkb:disabled ~ .checkmark:after {
/* I noticed that you had the disabled attribute set in your HTML so I've styled this gray so you know it's
not click-able */
color:lightgray;
}
<div class="checkOpt">
<label class="labelopt">
<input type="checkbox" name="plans[]" class="checkb " title="Transfer existing line - OFNL" id="a12" value="0.00" checked="checked" disabled="" autocomplete="off">
<span class="checkmark"></span>
</label>
</div>
<div class="checkOpt">
<label class="labelopt">
<input type="checkbox" name="plans[]" class="checkb " title="Paper Bill" id="a35" value="2.00" autocomplete="off">
<span class="checkmark"></span>
</label>
</div>
<div class="checkOpt">
<label class="labelopt">
<input type="checkbox" name="plans[]" class="checkb " title="Transfer existing line " id="a12X" value="0.00" autocomplete="off" checked="checked" disabled="disabled">
<span class="checkmark"></span>
</label>
</div>
I am trying to edit a form I have used many times but now I need to add checkboxes for options and I cannot for the life of me get them to align correctly or figure out where the formatting needs to be changed. I am not an expert at PHP, HTML, or CSS I was just tasked with this being in IT so I am learning as I am going. You guys have always came to my rescue on previous projects too and I am about a days worth deep into it with no changes. Made the checkboxes red in the CSS just so I could make sure a change I made to them went.
Basically want the checkboxes to look like this:
Project needs: [] Photography [] Videography [] Resize
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Marketing and Communications Request</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="marketing_style.css" />
</head>
<body>
<center>
<br /><br /><img src="logo.jpg" width="350px" height"100px"><br /><br />
<H1>Marketing and Communications Request</H1>
</center>
<div id="page-wrap">
<div id="contact-area">
<br />
<br />
<form method="post" action="marketing_contactengine.php">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" />
<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />
<label for="Phone">Phone:</label>
<input type="text" name="Phone" id="Phone" />
<label for="Dept">Department:</label>
<input type="text" name="Dept" id="Dept" />
<label for="Dir">Department Director:</label>
<input type="text" name="Dir" id="Dir" />
<label for="COID">COID/Account Code (GL Code):</label>
<input type="text" name="COID" id="COID" />
<br><br>
<br><br>
<h2><u>EVENT INFORMATION</u></h2>
<label for="EventName">Event Name:</label>
<input type="text" name="EventName" id="EventName" />
<label for="EventDateTime">Event Date & Time:</label>
<input type="text" name="EventDateTime" id="EventDateTime" placeholder="01/01/2021 08:00:00" />
<label for="EventLocation">Event Location:</label>
<input type="text" name="EventLocation" id="EventLocation" />
<label for="Desc">Brief description of the event:</label><br />
<textarea name="Desc" rows="2" cols="10" id="Desc"></textarea>
<br><br>
<br><br>
<h2><u>PROJECT INFORMATION</u></h2>
<label for="ProjectName">Project Name:</label>
<input type="text" name="ProjectName" id="ProjectName" />
<label for="Materials">Materials due date:</label>
<input type="text" name="Materials" id="Materials" />
<br />
</div>
<div id="checkboxes" class="checkboxes">
<label id="ProjectNeeds" for="ProjectNeeds" class="checkboxes">Project needs (check all that apply):</label>
<label class="checkboxes" for="Photography"><input type="checkbox" id="Photography" /> <span>Photography</span></label>
<label class="checkboxes" for="Videography"><input type="checkbox" id="Videography" /> <span>Videography</span></label>
<label class="checkboxes" for="Resize"><input type="checkbox" id="Resize" /> <span>Resize</span></label>
</div>
</div>
</div>
<div id="bottom" style="position: relative;">
<div style="position: absolute;">
Submission of this form is required for all requests to the marketing and communications team.
</div>
</body>
</html>
CSS:
body {
font-size: 62.5%;
font-family: Helvetica, sans-serif;
}
p {
font-size: 1.3em;
margin-bottom: 15px;
}
#page-wrap {
background: white;
padding: 20px 50px 20px 50px;
min-height: 500px;
height: auto !important;
height: 500px;
width: 700px;
}
#contact-area {
width: 660px;
margin-top: 25px;
}
#contact-area input, #contact-area textarea {
padding: 10px;
width: 471px;
font-family: Helvetica, sans-serif;
font-size: 1.4em;
margin: 0px 0px 10px 0px;
/* border: 2px solid #ccc; */
}
/* #contact-area textarea { */
/* height: 90px; */
/* } */
#contact-area textarea:focus, #contact-area input:focus {
border: 2px solid #900;
}
#contact-area input.submit-button {
width: 100px;
float: right;
}
label {
float: left;
text-align: right;
margin-right: 15px;
width: 100px;
padding-top: 10px;
font-size: 1.4em;
font-weight: bold;
}
#bottom {
font-family: Helvetica, sans-serif;
font-size: 1.4em;
margin: 0px 0px 0px 100px;
width: 900px;
padding-top: 75px;
padding-bottom: 75px;
text-align: left;
}
#checkboxes {
color: red;
}
In your CSS, you have a label {} declaration that is affecting all labels, including the ones next to your input radios. It is making them float and that's why they mess up.
To fix it you need to add another declaration that cancels the float for the labels inside #checkboxes, like so:
#checkboxes label {
float: none;
}
You have to set the label CSS properties like that:
label {
float: left;
text-align: right;
margin-right: 15px;
padding-top: 10px;
font-size: 1.4em;
font-weight: bold;
}
And add another CSS line:
.checkboxes input { float:left; vertical-align:middle; margin-right:10px; }
I have set when user types something in the search box, the suggestions will appear.
When suggestions appear, it will push the buttons and texts below down as I set its position relative.
But when user delete those words in the search box and the suggestion list disappears, the buttons and texts below the suggestion list did not move back to the original place.
How can I let the buttons and texts below the suggestion list move back to the original place when user delete those words in search box?
This is my current code:
<?php
include 'script_suggestion.php';
include 'script_close_suggestion_box.php';
?>
<html>
<head>
<title>
Brandon's Search Engine
</title>
<style type="text/css">
#suggestion {
border: 1px solid black;
visibility: hidden;
position: relative;
background-color: transparent;
z-index: 10;
}
.suggestion a {
font-size: 12pt;
color: black;
text-decoration: none;
display: block;
width: 648px;
height: auto;
text-align: left;
padding: 10px;
}
.suggestion a:hover {
background-color: #dddddd;
width: 644px;
padding: 2px;
}
</style>
</head>
<body>
<form method="GET" action="search.php" name="q">
<table align="center">
<div>
<h1><center>Brandon's Search Engine</center></h1>
</div>
<div align="center">
<input type="text" name="q" id="q" class="q" style="height: 27px; width: 650px; padding: 2px" placeholder="Search Now"
onkeyup="getSuggestion(this.value)" autocomplete="off" autoFill="on" onblur="closeBox()"/>
<script>document.getElementById('q').focus()</script>
<div id="suggestionBox" style="visibility: collapse;">
<div id="suggestion" style="width: 645px; text-align: left; padding: 2px;">
</div>
</div>
</div>
<br />
<div align="center">
<input type="submit" value="Search" name="submit" style="height: auto; width: 60px; padding: 2px" />
<input type="reset" value="Clear" onclick="closeBox()" style="height: auto; width: 50px; padding: 2px" />
</div>
<div align="center">
Can't find your site? <br /> Insert here.
</div>
</table>
<input type="hidden" name="page" value="1" />
</form>
</body>
</html>
Thanks in advance.
On your function in your onkeyup, you can check the text value and if that was empty change css position of your element to original:
function getSuggestion(value){
if(!value.length()){
//change to original place
}
.
.
.
}
I hope to help
I have no experience with php at all. Some html, some javascript, but that is it.
All I want to do is have a drop-down list for database connections and then based on that connect to the database chosen. Simple enough but I can't seem to get the select option value. I've gone down a huge rat hole trying to figure this out. everything points me to isset($_POST['somevariable']) to get the value but I think I'm missing something key. Do i need to be using the form tag or something. no matter what I do, I can't get at the variable. Also, can I just do this all in one php script? other posts have multiple php scripts. I ended up adding a submit button to see if that is it... I just am coming up empty.. I'm missing something really dumb...
Here is my code:
<html>
<head>
<title>Liferay Utilities</title>
<style>
.label {
font-weight: bold;
margin: 10px 20px 10px 0;
float: left;
clear: left;
width: 200px;
}
.element {
margin: 10px 0;
width: 150px;
float: left;
}
</style>
</head>
<body>
<h1>Liferay Utilities</h1>
<hr style="border-bottom: #cac917 5px solid;" />
<p class="label">Choose Database:</p>
<select name="dbtype">
<option value="default">Select Database</option>
<option value="suntest">SUNTEST</option>
<option value="sundevo">SUNDEVO</option>
</select>
<input type="submit" name="submit" value="Next">
</p>
<?php
//just debugging
echo 'xx';
echo isset($_POST['submit']);
echo 'xx';
if (isset($_POST['dbtype']))
{
// I NEVER EVER GET IN HERE
echo 'in here';
}
?>
</body>
</html>
Any Help would be greatly appreciated.
HERE IS MY NEW CODE: IT WORKS NOW!!! Thank you all! Wish I had posted an hour ago... If there are any good websites out there were full examples and real-world ones, let me know.
<html>
<head>
<title>Liferay Utilities</title>
<style>
.label {
font-weight: bold;
margin: 10px 20px 10px 0;
float: left;
clear: left;
width: 200px;
}
.element {
margin: 10px 0;
width: 150px;
float: left;
}
</style>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<h1>Liferay Utilities</h1>
<hr style="border-bottom: #cac917 5px solid;" />
<p class="label">Choose Database:</p>
<select name="dbtype">
<option value="default">Select Database</option>
<option value="suntest">SUNTEST</option>
<option value="sundevo">SUNDEVO</option>
</select>
<input type="submit" name="submit" value="Next">
</p>
<?php
echo $_SERVER['PHP_SELF'];
//just debugging
echo 'xx';
echo isset($_POST['submit']);
echo 'xx';
if (isset($_POST['dbtype']))
{
// I NEVER EVER GET IN HERE
echo 'in here';
}
?>
</form>
</body>
</html>
Try:
<form action="page.php" method="post">
<select name="dbtype">
<option value="default">Select Database</option>
<option value="suntest">SUNTEST</option>
<option value="sundevo">SUNDEVO</option>
</select>
<input type="submit" name="submit" value="Next">
</form>
in your php do echo $_POST["dbtype"]; to see if you get the correct result.
Change page.php for the name of the page you are submitting the form to.
You not defining the method. At the very least you must have that in order to use $_POST. To do that you must wrap your input/select in a form
<form method="post">
<select name="dbtype">
<option value="default">Select Database</option>
<option value="suntest">SUNTEST</option>
<option value="sundevo">SUNDEVO</option>
</select>
<input type="submit" name="submit" value="Next">
</form>
Note: Without giving an action attribute, the action will become the current page.