I have a form with dropdown choice
<select id="ubytovanie" name="ubytovanie">
<option value=""> </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>
In my form you can choose room number in which you would like to stay. But there can be only 6 people in one room, so I need to limit the option so max 6 people can choose same room number. After that, the option with room number would be disabled for other people filling out the form.
Is there a way to do this, ideally with PHP?
Thanks for answer
Related
I'm not sure why in the desktop is working, but on the phone, it showed like this 2 hrs + 2 oz
It seems like it loaded the default value 2. Even if the Chrome simulator showed the wrong only the mobile view. It's a float in the database.
see its value inside the db
Update
public function settingsUpdate($id){
$baby = Baby::where('uuid',$id)->first();
if($baby){
$baby->name = Request::get('name','');
$baby->phone = Request::get('phone','');
$baby->email = Request::get('email','');
$baby->babyName = Request::get('babyName','');
$baby->babyDob = Request::get('babyDob','').' '.Request::get('babyHob','').':00';
$baby->adminCode = Request::get('adminCode','');
$baby->readOnlyCode = Request::get('readOnlyCode','');
$baby->feedingInterval = (float) Request::get('feedingInterval',''); <<<---------- ✨
$baby->feedingAmount = (float) Request::get('feedingAmount',''); <<<---------- ✨
$baby->displayMode = Request::get('displayMode','');
$baby->save();
return Redirect::to('/baby/'.$baby->uuid.'?code='.$baby->adminCode);
} else {
return Redirect::to('/');
}
}
HTML/View
<div class="form-group">
<div class="col-xs-6">
<label for="feedingInterval"><h5>Feeding Interval <small class="helpText">(hours)</small></h5></label>
<select class="form-control" id="feedingInterval" name="feedingInterval">
<option value="2">2 hrs </option>
<option value="2.5">2.5 hrs </option>
<option value="3">3 hrs </option>
<option value="3.5">3.5 hrs </option>
<option value="4">4 hrs </option>
<option value="4.5">4.5 hrs </option>
<option value="5">5 hrs </option>
<option value="5.5">5.5 hrs </option>
<option value="6">6 hrs </option>
</select>
</div>
<div class="col-xs-6">
<label for="feedingAmount"><h5>Feeding Amount <small class="helpText">(ounces)</small></h5></label>
<select class="form-control" id="feedingAmount" name="feedingAmount">
<option value="2">2 oz </option>
<option value="2.5">2.5 oz </option>
<option value="3">3 oz </option>
<option value="3.5">3.5 oz </option>
<option value="4">4 oz </option>
<option value="4.5">4.5 oz </option>
<option value="5">5 oz </option>
<option value="5.5">5.5 oz </option>
<option value="6">6 oz </option>
</select>
</div>
</div>
GET
$('#feedingInterval').val(`{{$baby->feedingInterval}}`.toString());
$('#feedingAmount').val(`{{$baby->feedingAmount}}`.toString());
HTML:
<div class="select is-pulled-right" style="margin-top:-8px;"> <select id="pin_selection_1" name="pin_selection_1" class="is-pulled-right"> <option value="0"> 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> </select> </div><div class="select is-pulled-right" style="margin-top:-8px;"> <select id="pin_selection_2" name="pin_selection_2" class="is-pulled-right"> <option value="0"> 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> </select> </div><div class="select is-pulled-right" style="margin-top:-8px;"> <select id="pin_selection_3" name="pin_selection_3" class="is-pulled-right"> <option value="0"> 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> </select> </div><div class="select is-pulled-right" style="margin-top:-8px;"> <select id="pin_selection_4" name="pin_selection_4" class="is-pulled-right"> <option value="0"> 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> </select> </div><div class="select is-pulled-right" style="margin-top:-8px;"> <select id="pin_selection_5" name="pin_selection_5" class="is-pulled-right"> <option value="0"> 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> </select> </div><div class="select is-pulled-right" style="margin-top:-8px;"> <select id="pin_selection_6" name="pin_selection_6" class="is-pulled-right"> <option value="0"> 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> </select> </div>
PHP:
if ($request->input('pin_severity') != 'disabled') {
$user->pin_code =
$request->input('pin_selection_6') .
$request->input('pin_selection_5') .
$request->input('pin_selection_4') .
$request->input('pin_selection_3') .
$request->input('pin_selection_2') .
$request->input('pin_selection_1');
}
$user->save();
echo 'pin_selection_1: ' . $request->input('pin_selection_6') . '<br>';
echo 'pin_selection_2: ' . $request->input('pin_selection_5') . '<br>';
echo 'pin_selection_3: ' . $request->input('pin_selection_4') . '<br>';
echo 'pin_selection_4: ' . $request->input('pin_selection_3') . '<br>';
echo 'pin_selection_5: ' . $request->input('pin_selection_2') . '<br>';
echo 'pin_selection_6: ' . $request->input('pin_selection_1') . '<br>';
exit();
I use 6 different select dropdowns to pick a 6 digit pin code, when saving it using the PHP code I am receiving some issues. My database column is an int with length 6 NOT NULL.
When saving the pin as something like 123456 or 223344 it works perfectly and saves correctly. Earlier I tried doing something more complicated, 020304
It went through, but saved in the database as 20304, the strange thing is, my echo displayed it exactly as I entered it, but it saved in the database incorrectly?
Your echos are displayed correctly because they act as strings.
But when you save the pin in your database, Laravel/mysql converts the string to an integer, hence, the mismatch.
If you want it to be inserted as is, change the datatype of your pin_code column to varchar
My html code is like below
<select multiple="multiple" size="2" name="exServer[]">
<option value="1"> host.newcybage.alabanza.com </option>
<option value="2"> host2.newcybage.alabanza.com </option>
<option value="3"> host3.newcybage.alabanza.com </option>
<option value="5"> host3.devel.php5.qa.alabanza.com </option>
<option value="7"> centos5host2.alabanza.com </option>
<option value="8"> centos5host.template.alabanza.com </option>
</select>
<input type="submit" value="Apply" name="exSubmit" class="button">
And my php code is like below
$arr=$_POST['exServer'];
print_r($_POST['exServer']);
print_r($arr);
Both print statements are giving me no results.
I dont know where i am wrong in getting selected multiple dropdown values.
I verified using HttpFox that data is getting posted properly on server side.
When i am printing value of exSubmit, it is giving me proper values.
print "Exsubmit:".$_POST['exSubmit']; //Result Exsubmit:Apply
Please help.
you code is working. I tried this and got all the selected values in PHP
<?php
$arr=$_POST['exServer'];
print_r($_POST['exServer']);
print_r($arr);
?>
<form method="post">
<select multiple="multiple" size="2" name="exServer[]">
<option value="1"> host.newcybage.alabanza.com </option>
<option value="2"> host2.newcybage.alabanza.com </option>
<option value="3"> host3.newcybage.alabanza.com </option>
<option value="5"> host3.devel.php5.qa.alabanza.com </option>
<option value="7"> centos5host2.alabanza.com </option>
<option value="8"> centos5host.template.alabanza.com </option>
</select>
<input type="submit" value="Apply" name="exSubmit" class="button">
</form>
This should work
<select multiple="multiple" size="2" name="exServer[]">
<option value="1"> host.newcybage.alabanza.com </option>
<option value="2"> host2.newcybage.alabanza.com </option>
<option value="3"> host3.newcybage.alabanza.com </option>
<option value="5"> host3.devel.php5.qa.alabanza.com </option>
<option value="7"> centos5host2.alabanza.com </option>
<option value="8"> centos5host.template.alabanza.com </option>
</select>
My suggestion is to print the array $_POST and see the values passed in the backend.
<?php
print_r($_POST);
?>
Ok so I have some code that works perfectly for the first product I added into my store. But when I add the next product the drop down options auto increment the ID value in the selection. I need to find a way around this so it works on any product that is loaded.
Here is the Javascript:
<script language="javascript">
function displayCondition() {
condition = new Array("Please Select a Condition.","<b>Perfect:</b> Text to explain perfect condition!", "<b>Excellent:</b> Text to explain excellent condition!", "<b>Good:</b> Text to explain good condition!", "<b>Poor:</b> Text to explain poor condition!", "<b>Broken:</b> Text to explain broken condition!");
var getsel = document.getElementById('select_<?php echo $_option->getId();?>').value;
document.getElementById("divId").innerHTML = condition[getsel];
}
</script>
Here is the working products code notice the IDs are 1-5:
<select name="options[1]" id="select_1" class=" required-entry product-custom-option"
title="" onchange="opConfig.reloadPrice();displayCondition()">
<option value="" >-- Please Select --</option>
<option value="1" price="0" >Perfect </option>
<option value="2" price="-35" >Excellent </option>
<option value="3" price="-105" >Good </option>
<option value="4" price="-140" >Poor </option>
<option value="5" price="-252" >Broken </option>
</select>
And the code for the second product. Each product after this will keep incrementing:
<select name="options[6]" id="select_6" class=" required-entry product-custom-option"
title="" onchange="opConfig.reloadPrice();displayCondition();">
<option value="" >-- Please Select --</option>
<option value="13" price="0" >Perfect </option>
<option value="14" price="-35" >Excellent </option>
<option value="15" price="-105" >Good </option>
<option value="16" price="-140" >Poor </option>
<option value="17" price="-252" >Broken </option>
</select>
The help I need is in the javascript. I can not change the values in the select's since they control the pricing that will affect each product. Thank you in advance.
I am trying to create a form that will automatically calculate points based on the options chosen
this is what i came up with but so far it doesn't seem to work
<html>
<head>
<link rel="stylesheet" href="style000.css" type="text/css" media="screen" />
</head>
<body>
<form name="form">
<label>Age</label>
<select name='g'>
<option value='' >Select One</option>
<option value='0' >Less than 17</option>
<option value='2' >17</option>
<option value='4' >18</option>
<option value='6' >19</option>
<option value='8' >20</option>
<option value='10' >21-49</option>
<option value='8' >50</option>
<option value='6' >51</option>
<option value='4' >52</option>
<option value='2' >53</option>
<option value='0' >54+</option>
</select>
<label>Education</label><select name='a'>
<option value='' selected='selected'>Select one</option>
<option value='0' >No High School</option>
<option value='5' >Secondary School</option>
<option value='12' >One Year Diploma, apprenticeship AND 12 years full time study</option>
<option value='15' >One Year Diploma, apprenticeship AND 13 years full time study</option>
<option value='15' >Bachelors Degree from University AND 13 years full time study</option>
<option value='20' >2 year diploma AND 14 years full time study</option>
<option value='20' >2 year bachelor's degree from university AND 14 years full time study</option>
<option value='22' >3 year diploma AND 15 years full time study</option>
<option value='22' >2 bachelor degrees from university and 15 years full time study</option>
<option value='25' >PhD or Masters & 17 years full time study</option>
</select>
<h3><strong>Primary Language</strong></h3>
<label>Speaking</label>
<select name="c">
<option value='' >Select One</option>
<option value='4' >6.5+</option>
<option value='2' >5.5 – 6.0</option>
<option value='1' >4.0 – 5.0</option>
<option value='0' >Less than 4.0</option>
</select>
<label>Listening</label>
<select name="d">
<option value='' selected='selected'>Select One</option>
<option value='4' >7.5+</option>
<option value='2' >5.5 – 7.0</option>
<option value='1' >4.5 – 5.0</option>
<option value='0' >Less than 4.5</option>
</select>
<label>Reading</label>
<select name="e">
<option value='' >Select One</option>
<option value='4' >6.5+</option>
<option value='2' >5.0 – 6.0</option>
<option value='1' >3.5 – 4.5</option>
<option value='0' >Less than 3.5</option>
</select>
<label>Writing</label>
<select name='f'>
<option value='' >Select One</option>
<option value='4' >6.5+</option>
<option value='2' >5.5 – 6.0</option>
<option value='1' >4.0 – 5.0</option>
<option value='0' >Less than 4.0</option>
</select>
<h3><strong>Work</strong></h3>
<label>Work Experience</label>
<select name="b">
<option value=''>Select One</option>
<option value='0' >Less than 1 year</option>
<option value='15' >1 Year</option>
<option value='17' >2 Years</option>
<option value='19' >3 Years</option>
<option value='21' >4 Years or more</option>
<label>Arranged Employment</label>
<select name="l">
<option value=''>Select One</option>
<option value='10'>Yes</option>
<option value='0'>No</option>
</select>
<h3><strong>Adaptability</strong></h3>
<label>Spouse's Education</label>
<select name="h">
<option value='' >Select One</option>
<option value='0' >Secondary School</option>
<option value='3' >One Year Diploma, apprenticeship AND 12 years full time study</option>
<option value='3' >Bachelors Degree from University AND 13 years full time study</option>
<option value='4' >A two-year diploma, trade certificate or apprenticeship or university degree at the bachelor's level and completed at least 14 years of full-time or full-time equivalent studies</option>
<option value='4' >A three-year diploma, trade certificate or apprenticeship (not university) and completed at least 15 years of full-time or full-time equivalent studies</option>
<option value='4' >Two or more university degrees at the bachelor's level and completed at least 15 years of full-time or full-time equivalent studies</option>
<option value='5' >A master's or Ph.D. and completed at least 17 years of full-time or full-time equivalent studies</option>
<option value='0' >No Education</option>
</select>
<label>Applicant OR Spouse has studied in Canada</label>
<select name='i'>
<option value='5'>Yes, more than two years post secondary after the age of 17.</option>
<option value='0'>Yes, but for less than two years</option>
<option value='0'>No</option>
</select>
<label>Applicant OR Spouse has worked in Canada</label>
<select name="j">
<option value='' selected='selected'>Select One </option>
<option value='5'>Worked full-time in Canada for at least one year</option>
<option value='0'>Yes, but for less than 1 year</option>
<option value='0'>No</option>
</select>
<label>Applicant or Spouse has Family in Canada</label>
<select name="k">
<option value='' selected='selected'>Select One</option>
<option value='5'>Yes</option>
<option value='0'>No</option>
</select>
<INPUT NAME="calc" VALUE="Calculate" TYPE="button" onClick="compute(this.form)">
<input name="rslt" type="text" style="font-size: 50px" value="" size="5" readonly="readonly">
<h3 style="font-size: 50px">points</h3>
</form>
<script language="JavaScript">
<!-- hide this script from old browsers
function compute(form)
{
var a = parseInt(form.a.value);
var b = parseInt(form.b.value);
var c = parseInt(form.c.value);
var d = parseInt(form.d.value);
var e = parseInt(form.e.value);
var f = parseInt(form.f.value);
var g = parseInt(form.g.value);
var h = parseInt(form.h.value);
var i = parseInt(form.i.value);
var j = parseInt(form.j.value);
var k = parseInt(form.k.value);
var l = parseInt(form.l.value);
f = (a + b + c + d + e + f + g +h + j + k + l);
form.rslt.value = f;
}
// done hiding from old browsers -->
</script>
</body>
</html>
what am i doing wrong is there an other way of doing it with javascript or PHP, preferably javascript
thanks
Your <select name="b"> element is missing its closing </select> tag, so the following <select name="l"> element is lost, and you're getting an Error when you try to do form.l.value.
Proper indentation helps avoid such issues.
Note that you may want to do this:
var a = parseInt(form.a.value, 10) || 0;
var b = parseInt(form.b.value, 10) || 0;
var c = parseInt(form.c.value, 10) || 0;
var d = parseInt(form.d.value, 10) || 0;
// and so on
...so you don't get NaN if some value is "" and to ensure base 10.