it is only displaying the first select box and the last one ..
here is the code.
function select_nom_of_guests($guest_type){
$i=0;
echo $guest_type;
echo "<select name=\"adults_num\" id= \"a\">";
while ($i<=5){
echo "<option value= $i>$i</option>" ;
$i++;
}
}
echo "<p>";
select_nom_of_guests("מספר מבוגרים");
select_nom_of_guests("מספר ילדים");
select_nom_of_guests("מספר תינוקות");
echo "</p>";
Close your <select> tags and it should work better ;-)
Note that a for loop would be more appropriate in your case.
Note that you don't end the <select> tag. I'm not sure how browsers would respond to that, but it definitely wouldn't help.
One helpful tool in these scenarios is the View Source tool that all major browsers have: instead of being confused about what's appearing on the screen, look at the HTML that the browser received to see why it might be showing what it's showing. If this is the issue, the source code would have revealed it lickity-split :)
You didn't close the select tag. You probably also want to make the name and id attributes different for each select.
function select_nom_of_guests($guest_type){
$i=0;
echo $guest_type;
echo "<select name=\"adults_num".$guest_type."\" id= \"select_".$guestType."\">";
while ($i<=5){
echo "<option value= $i>$i</option>" ;
$i++;
}
echo "</select>";
}
Related
I'm stuck with, what I think, should be something basic. But i can't, for the love of anything, get it to work.
:
echo "<tr><td>Aktiv</td><td>";
echo "<select class=left size=1 name=active>";
echo "<option value=1>aktiv</option>";
echo '<option value=0 selected>inaktiv</option>';
echo "</select>";
echo "</td></tr>";
:
I just want to create a dropdown and preselect the "inaktiv" option.
The funny part is, when using it on my Work-PC, this will still preselect "aktiv".
When i throw this in any kind of other thing, even the most basic online "compiler", it will do just fine.
Are there mybe any kind of kompatibility issues with this on like older versions of Firefox or something like that?
I coded adding comments function to RSS articles
In the twists and turns, it is in php coding to show and enter comments. However, the input box does not appear.
Here is the php code:
$url = "./comments/" . $q.".txt";
//댓글 파일에서 컨텐츠 문자열 가져오기
$txtcomment = file_get_contents($url,true);
//댓글 나열
echo "<ol>";
if ($q !== "" ) {
$comm = $txtcomment;
$arr = [];
$arr = explode("--",$comm);
for ($i=4;$i<count($arr);$i++) {
echo "<li>".$arr[$i]."</li>";
}
} else {
echo "해당기사가 없습니다.";
}
echo "</ol>";
//중첩검색&결과내 검색 폼 만들기
echo "<br><form class=\"category B\" >
Comment: <input type=\"text\" name=\"comment1\" id=\"comment1\" onkeyup=\"inputComment()\" >
</form>";
Why?
Thank for your concern.
Since I use RSS, I presume that php does not properly pass the attributes of the input tag in between. I started to change the old coding.
In other words, I decided that the Show Comments and the input comments were different from the beginning.
getrss.php code as below at first.
echo " <option id=".$i." onclick=\"showComment".$i."(this.value)\" value=".$item_link4."> Show Comments </option>";
but, I added the input code as like
echo " <option id=".$i." onclick=\"showComment".$i."(this.value)\" value=".$item_link4."> Show Comments </option>";
echo "댓글: <input type='text' name='inputComment' size='200' id='input".$i."' onclick='inputComment".$i."(this.value)' >
<input type='text' name='txtfile' id='txt".$i."' value=".$item_link4." hidden>
<div id='comment".$i."'><b>information will be listed here.</b></div>";
And, I make input box as a below picture.
In the end, I am trying to solve the problem in a roundabout way.
But, I still wonder why ajax's ajax is not working!!
After I input my comment, at once I see that.
further coding makes a below picture.
Thanks a lot for your sharing.
I have a strange problem which I presume is to do with my setup (WAMP on Windows 10). I am a beginner and working on my first project (rewriting an old Access/VBA solution).
I want to create an HTML drop down list on the fly - mysqli_query works fine and I can echo the list I need and get an accurate row count. But when I try any echo statement which starts with a '<' the rest of the page doesn't run.
The < is fine anywhere else but at the beginning. What I need is to be able to put
while($row = mysqli_fetch_assoc($result)) {
echo "<option value ='".$row['schoolName']."'>".$row["schoolName"]."</option>";
}
This just displays a list of $row["schoolName"] biut no other text.
There may be some mistakes in that code but I have tested this with much shorter echo strings and they always fail if '<' is the first thing after echo. I don't get an error message - the code above just gives a correct list of $row['schoolName].
Any ideas?
Try this
<select name="" id="input" class="form-control">
<?php
while($row = mysqli_fetch_assoc($result)) {
echo "<option value ='".$row['schoolName']."'>".$row["schoolName"]." </option>";
}
?>
</select>
You must add the <select> tag before using an <option> tag.
<select name="" class="">
<?php
while($row = mysqli_fetch_assoc($result)) {
echo "<option value ='".$row['schoolName']."'>".$row["schoolName"]."</option>";
}
?>
</select>
I badly need your help on this.
I can't seem to find what's wrong in my code.
The case is, I am trying to populate my textbox field based on my combobox value and it is connected in sql database. I have tried some codes on the web and then I found a code which seems accurate but I can't seem to display the result on my textbox.
here is my HTML Code:
<?php
echo"Concept Store:";
echo "<select width='100' id='strs' name='strs' >";
echo "<option></option>";
while($row=sqlsrv_fetch_array($stmt))
{
$x= $row['strnm'];
echo " <option> $x</option>" ;
}
echo "</select>";
?>
Address    : <input type="text" id="add" name="add" size="27" /><br><br>
here's the AJAX:
<script type="text/javascript">
$(document).ready(function(){
$('#strs').change(function(){
$.post("gadd.php",{strs:$(this.val() )},function(result){
$("#add").val(result);
});
});
});
</script>
and here's my 'gadd.php'
<?php
session_start();
include ('sqlconn.php');
$gadd=$_post['strs'];
//$t1= mysql_real_escape_string($t1);
$sql="Select distinct dadd1 from ostore where strnm='".$gadd."' ";
$stmt = sqlsrv_query($conn,$sql);
//echo "<option></option>";
while ($row = sqlsrv_fetch_array($stmt))
{
// $type2=$row['dadd1'];
echo $row['dadd1'];
//echo '<option value ="'.$type2.'">'.$type2.'</option>';
}
?>
if you could help me, that would be really really awesome thank you!
Check it. Global variables should be in upper case.
$gadd = $_POST['strs'];
First, make sure you use the proper format for global variables $gadd = $_POST['strs'];
Second, check your query if it is working, try this
$sql=("Select distinct dadd1 from ostore where strnm = '$gadd'");
Most problably it's because you're missing the value in the option.
Use this:
echo " <option value='$x'> $x</option>" ;
instead of this:
echo " <option> $x</option>" ;
If still don't work, like was said before check if the query is working.
You can do that in chrome by the option "Inspect element" and the go to the "Network" tab. You can see what is sent through ajax and the return data.
I have a PHP script which connects to a MySQL database and creates an HTML dropdown list with data retrieved from it. The script works, I just don't understand how I'm supposed to use it in an HTML form.
The PHP script, named CountryList.php, looks like this:
<?php
function createCountryList() {
$con = mysql_connect("localhost","user","pass");
mysql_select_db('database', $con);
$sql="SELECT Country FROM CountryList";
$result = mysql_query($sql,$con);
echo "<select name=country value=''>Country</option>";
echo "<option value=0>Select Country</option>";
echo "<option value=1></option>";
$curvalue=2;
while($nt=mysql_fetch_array($result)){
echo "<option value=$curvalue>$nt[Country]</option>";
$curvalue = $curvalue+1;
}
echo "</select>";
mysql_close($con);
}
?>
I tried including the PHP file in the head of the HTML page with:
<?php include("CountryList.php"); ?>
And then I tried calling the function which creates the dropdown menu in a form later on:
<form action="insert.php" method="POST">
<label>Which country are you from?</label>
<?php createCountryList(); ?>
</form>
Since nothing happens, I did it wrong. Any advice? Help is appreciated.
EDIT: Bah, I knew it was something silly. The page was an HTML file, PHP didn't process it. Changing the HTML file to PHP solved everything.
What happens when you change this line
echo "<select name=country value=''>Country</option>";
to this
echo "<select name='country'>Country";
Are you sure its in the same folder. Its a good practice to do a check before
if ((include 'CountryList.php') == 'OK') {
createCountryList();
}
else{
echo "Didnt import";
}
Dont do brackets like include()
Try changing echo "<option value=$curvalue>$nt[Country]</option>"; to echo "<option value=$curvalue>{$nt['Country']}</option>";
Echoing out arrays requires curly brackets around the array index if inside a string. Also the index needs quotes or php will assume constant.
This is what I did in one of my HTML forms. Try and see if it works for you.
<select name="country"><?php createCountryList();?></select>
What you do here is on the page where you want the selectbox, you put in this code and call the function.