How can I add html value for select menu options:
<select name="symbol">
<option>select</option>
<option value="<img src="start.jpg"">start</option>
<option value="<img src="end.jpg"">end</option>
</select>
I want post value to show an image.
I read this : How to add a images in select list
but I want send image value.
If you're handling the post with PHP or some similar server-side code, you should pass through only the reference to the image. Any tags can be output using the server-side code. For example:
<select name="symbol">
<option>select</option>
<option value="start.jpg">start</option>
<option value="end.jpg">end</option>
</select>
And then handle this by doing something like:
echo '<img src="'.$_POST['symbol'].'" />';
Use single quotes instead of double qoutes inside value...
<select name="symbol">
<option>select</option>
<option value="<img src='b.jpg'>">start</option>
<option value="<img src='a.jpg'>">end</option>
</select>
You have to use single quote and close tag. Try this,
<select name="symbol">
<option>select</option>
<option value="<img src='start.jpg'>">start</option>
<option value="<img src='end.jpg'>">end</option>
</select>
Related
Posting the selected html option attribute via php..Here is my html code and I'm trying to select one option from the event-drop down menu, but really finding it hard to configure with php variable $event. Any help will be much appreciated.
HTML Code:
<div>
<h4>Event</h4>
<p class="cd-select icon">
<select class="budget">
<option value="0">Select Occasion</option>
<option value="1">alpha</option>
<option value ="2">Bravo</option>
<option value="3">Charlie</option>
<option value="4">Delta</option>
</select>
</p>
</div>
PHP version
$event = $_POST['selected'];
In PHP form fields are posted with their name. In your case you'd have to add the name attribute to the select.
<select class="budget" name="selected">
<option value="0">Select Occasion</option>
<option value="1">alpha</option>
<option value ="2">Bravo</option>
<option value="3">Charlie</option>
<option value="4">Delta</option>
</select>
My Multiselect input code is
<?php echo $this->Form->input('Dispensary.role.',array('options'=>$dispensary_users,'class'=>'form-control dispensary_users_dd','label'=>false,'style'=>'width:300px;','empty'=>'Select Users'));
?>
and generated html code :
<select name="data[Dispensary][role][]" class="form-control dispensary_users_dd" style="width: 300px; display: none;" id="DispensaryRole">
<option value="">Select Users</option>
<option value="9">Yashobanta</option>
<option value="80">Yash</option>
<option value="83">Ramesh</option>
</select>
But when I select all users, and print_r($this->data);
returns last selected input.
But I want all.
I forgot to add multiple => true.
I don't know how that thing with $this->Form->input(...); works, because it's not important. You can select only one opinion without multiple attribute.
Example by w3schools.org:
<select name="cars" multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
For saving the multiple select value in database, store the array using implode function.
In controller:
if (!empty($this->data)) {
$this->data['Category']['name'] = implode(",",$this->data['Category']['name']);
$this->Category->create();
$this->Category->save($this->data);
}
Hope it's help :)
I have the following in my HTML form, among with other inputs, like <input type="test" name="foo"></input> and others.
<select name="tags" multiple="multiple">
<option selected="selected" value="hello">hello</option>
<option selected="selected" value="world">word</option>
</select>
The problem is that when I am using
var_dump($_POST);
the tags returned is a string, and it contains only the last item in the select, like this:
string(5) "world"
Any help?
Your HTML should indicate that it's submitting an array :
<select name="tags[]" multiple="multiple">
(note the [])
Try using below code. Name should be name="tags[]". If you name is like name="tags" it will only pass one value, if you want to pass multiple values you should name it as an array.
<select name="tags[]" multiple="multiple">
<option selected="selected" value="hello">hello</option>
<option selected="selected" value="world">word</option>
</select>
Your code should look like:
<select name="tags[]" multiple="multiple">
<option selected="selected" value="hello">hello</option>
<option value="world">word</option>
</select>
And please don't use selected="selected" for every option. Selected="selected" should be used only for one option, the option to be shown default! This is very important!
use name="tags[]" that way an array is passed
then you can use
if(isset($_POST['tags'])){
foreach($_POST['tags'] AS $value){
echo $value;
}
}
In this case be sure to set method="post" in your form tag.
You can use selected="selected" without a problem
i'm having the following html markup:
<select id=gender>
<option value=''>Please select</option>
<option value='m'>male</option>
<option value='f'>female</option>
</select>
i want to set the value using the simple html dom parser - here's my code - which doesn't work:
$combo = $el->find("#gender",0);
$combo->value = "m";
i also tried $combo->setAttribute('value', 'm'); without success
any ideas?
thanks
<select> has no value attribute. What you need to do is find the option you want selected (e.g. something like #gender/option[value='m']) and set the selected attribute on that.
In order to set the selected option out of a <select>, you need to set selected on the corresponding <option>:
<select id=gender>
<option value=''>Please select</option>
<option value='m' selected>male</option>
<option value='f'>female</option>
</select>
<div>
<select name="mySelect" id="mySelect" class="select" onchange="if(this.options[this.selectedIndex].value != ''){window.top.location.href=this.options[this.selectedIndex].value}">
<option value="english.php">English</option>
<option value="french.php">French</option>
<option value="spanish.php">Spanish</option>
</select>
</div>
i want to change language it work fine when i change the language but in dropdown it always shows english
Add a selected attribute to the option you want to be selected when the page loads.
You need to add another tag that is blank.
Working example:
http://jsfiddle.net/XYSXA/
<select name="mySelect" id="mySelect" class="select" onchange="if(this.options[this.selectedIndex].value != ''){window.top.location.href=this.options[this.selectedIndex].value}">
<option value=""></option>
<option value="english.php">English</option>
<option value="french.php">French</option>
<option value="spanish.php">Spanish</option>
</select>
This way none of the options will be selected by default.
Alternatively, you may use the set the attribute selected inside one of the opening <option> tags to specify which language should be selected by default. Example selecting French by default:
<select name="mySelect" id="mySelect" class="select" onchange="if(this.options[this.selectedIndex].value != ''){window.top.location.href=this.options[this.selectedIndex].value}">
<option value=""></option>
<option value="english.php">English</option>
<option value="french.php" selected>French</option>
<option value="spanish.php">Spanish</option>
</select>
Working example: http://jsfiddle.net/XYSXA/1/
<?
$file=basename($_SERVER['PHP_SELF'],".php");
$file=ucwords($file);
?>
<option value="french.php" <?=($file=="French")?" selected='selected'":""?>>French</option>
I m assuming that you're using the pattern like French for french.php, Spanish For spanish.php,etc