Option Value placed outside of quotes - html

While I am sure I am doing something stupid, after staring at the code for much too long, I am now stumped. I have created a select box and populate it with posts from a certain post type in Wordpress. This works fine except when viewing the source, the option value is being placed outside of the actual value attribute and all boxes are being marked as selected.
It has to be a simple mistake somewhere but if anyone can spot this, it would be greatly appreciated.
<label for="meta-select-providers" class="package-row-title"><?php _e( 'Provider', 'package_textdomain' )?></label>
<select name="meta-select-providers" id="meta-select-providers">
<?
if( $providers->have_posts() )
{
while( $providers->have_posts() )
{
$providers->the_post();
$provider_name = get_the_title();
$provider_id = the_ID();
?>
<option value="<? echo $provider_id; ?>" <?php if (isset ($package_stored_meta['meta-select-providers'])) selected( $package_stored_meta['meta-select-providers'][0], $provider_id ); ?>>
<?php _e( $provider_name, 'package_textdomain' )?></option>
<?
}
}
?>
</select>
Update
<option value="<? the_ID(); ?>" <?php if (isset ($package_stored_meta['meta-select-providers'])) selected( $package_stored_meta['meta-select-providers'][0], the_ID() ); ?>>
<?php _e( $provider_name, 'package_textdomain' )?></option>
Source:
1647
<option value="" selected>
Post 1</option>
1645
<option value="" selected>
Post 2</option>
1643
<option value="" selected>
Post 3</option>

the_ID() displays (echoes) the value. From the docs:
Displays the numeric ID of the current post. This tag must be within The Loop.
Note: This function displays the ID of the post, to return the ID use get_the_ID().
This code will work as expected:
<label for="meta-select-providers" class="package-row-title"><?php _e( 'Provider', 'package_textdomain' )?></label>
<select name="meta-select-providers" id="meta-select-providers">
<?
if( $providers->have_posts() )
{
while( $providers->have_posts() )
{
$providers->the_post();
$provider_name = get_the_title();
$provider_id = get_the_ID();
?>
<option value="<? echo $provider_id; ?>" <?php if (isset ($package_stored_meta['meta-select-providers'])) selected( $package_stored_meta['meta-select-providers'][0], $provider_id ); ?>>
<?php _e( $provider_name, 'package_textdomain' )?></option>
<?
}
}
?>
</select>

Related

can we make slider in select options?

can we make slider/carousel in select options.below is the code and image.anyone help plz.
<select class="" id="project_type" name="project_type" title="Project Type" multiple
style="width: 410px;">
<option value="Residential" <?php if($selected_project_type == 'Residential') echo "selected";
?> >Residential</option>
<option value="Commercial" <?php if($selected_project_type == 'Commercial') echo "selected"; ?
> >Commercial</option>
<option value="Residential & Commercial" <?php if($selected_project_type == 'Residential &
Commercial') echo "selected"; ?> >Residential & Commercial</option>
<option value="Infrastructure" <?php if($selected_project_type == 'Infrastructure') echo
"selected"; ?> >Infrastructure</option>
<option value="Others" <?php if($selected_project_type == 'Others') echo "selected"; ?>
>Others</option>
enter image description here
i want all select options inline and put slider.
Selects are pretty hard to customize
A way easier will be just make slider
and change an input or even div properties when click on slide

how to keep selected value in select box after submit or page reload were values and option are different which retrieved from db?

I want to keep selected particular value which was selected before the form submission. But after reloading or submisssion i did not get the previous selected value.help me!
<select name="select" class="dropbtn" onchange="this.form.submit()">
<?php
include 'connect.php';
$query="SELECT * FROM `user` WHERE id =1";
$result=mysqli_query($link_id,$query);
while($data = mysqli_fetch_assoc($result))
{ ?>
<option value="<?php echo $data['user_id']; ?>"> <?php echo
$data['address']; ?> </option>
<?php } ?>
</select>
<?php
$id = null;
if(isset($_POST['select']))
{
$id = $_POST['select'];
echo $id;
}
?>

How to pass a query from a form to a dropdown in wordpress?

I'm using WP Job Manager to do this but I want to do a salary search from another page
https://wpjobmanager.com/document/tutorial-creating-custom-job-search-form/
this is the form, it uses a query string, it works with normal text boxes but with this Salary form I can't get it to work?
<div class="search_categories">
<label for="search_categories"><?php _e( 'Salary', 'wp-job-manager' ); ?></label>
<select name="filter_by_salary" class="job-manager-filter">
<option value=""><?php _e( 'Any Salary', 'wp-job-manager' ); ?></option>
<option value="upto20"><?php _e( 'Up to $20,000', 'wp-job-manager' ); ?></option>
<option value="20000-40000"><?php _e( '$20,000 to $40,000', 'wp-job-manager' ); ?></option>
<option value="40000-60000"><?php _e( '$40,000 to $60,000', 'wp-job-manager' ); ?></option>
<option value="over60"><?php _e( '$60,000+', 'wp-job-manager' ); ?></option>
</select>
</div>

how to submit dropdown form without submit button and without refresh

I need your help
I am using Onchange in a form to submit a dropdown data to the database, but something boring when i select the data the page get refreshed, so if i was down the page then after selecting the page takes me up again before i finish the next stage on my process.
So i need the help if anyone knows how can i do to stop that, that when i will select the dropdown data the page should remain without refresh it will be well and good!
I think Ajax does this but im not that much aware with AJAX
Here is my codes
<html>
<form action="" method="post" style="height:1px;">
<input name="key" type="hidden" value="<?php echo $id; ?>" />
<select name="Idadi"style="width:65px;" onchange="this.form.submit();">
<option value="1" <?php if($Idadi=="1") { echo "selected"; } ?> >1</option>
<option value="2" <?php if($Idadi=="2") { echo "selected"; } ?> >2</option>
<option value="3" <?php if($Idadi=="3") { echo "selected"; } ?> >3</option>
<option value="4" <?php if($Idadi=="4") { echo "selected"; } ?> >4</option>
<option value="5" <?php if($Idadi=="5") { echo "selected"; } ?> >5</option>
</select>
</form>
<?php
include('dbconnection.php');
if(isset($_POST['key'])){
$idlogin=$_POST['key'];
$idadi=$_POST['Idadi'];
$idadiquery="update `itemreg` set `Idadi` = '$idadi' where `id` ='$idlogin'";
$idadiresult = mysql_query($idadiquery);
if($idadiresult){
echo ""; // print massage
}
}
?>

html select list selected item and maximum value can be selected

HELLO,
i have an html select list, and i want: the selected number to be a given value $content->number, and the maximum value to be $content->product_type->stock_2 if it is less than 5, or 5 if it is greater than 5.
now i have:
<select class="number" name="number">
<? $max = $content->product_type->stock_2 > 5 ? 5 : $content->product_type->sale_stock; ?>
<option value="<?= $content->number ?>"><?= $content->number; ?> </option>
<? for ($i = 1; $i <= $max; $i++):?>
<option <?php if($content->product_type->stock_2 == $i) echo 'selected="selected"' ;?> value="<?= $i ?>"><?= $i; ?></option>
<? endfor; ?>
</select>
but it shows me twice the selected value $content->number. i'm sure i am mistaking somewhere.
Any suggestions?
thank you!
I do not know whether I correct understood what you want to do, but try this:
<select class="number" name="number">
<? $max = $content->product_type->stock_2 > 5 ? 5 : $content->product_type->sale_stock; ?>
<option value="<?= $content->number ?>"><?= $content->number; ?> </option>
<? for ($i = 1; $i <= $max; $i++):?>
<? if ($i != $content->number): ?>
<option <?php if($content->product_type->stock_2 == $i) echo 'selected="selected"' ;?> value="<?= $i ?>"><?= $i; ?></option>
<? endif; ?>
<? endfor; ?>
</select>