*I have to display US states in dropdown in .ftl file.I have stored data as key value pair in properties file as given below. I have to read data from properties file and display in ftl file.
AL=Alabama
AK=Alaska
AZ=Arizona
AR=Arkansas
CA=California
CO=Colorado
CT=Connecticut
DE=Delaware
DC=District of Columbia
//I have to display drop-down as given below.I am beginner to free-marker.Could anyone please help me to do that.
<select>
<option value=AL>Alabama</option>
<option value=AK>Alaska</option>
.
.
</select>
If you are using a framework that provide a select tag you can use it like this:
<form:select items="${countryMap}" /> <!-- SpringMVC -->
<#s.select list="countryMap" /> <!--Struts2 -->
where countryMap in both cases is a key-value Map exposed (available) to the template where you have read and stored your properties.
In pure freemarker would be like this:
<select>
<#list countryMap as key, value>
<option value="${key}">${value}</option>
</#list>
</select>
Also this page can help you.
Related
Here is my code.
PHP CODE
$smarty->assign('myOptions', array(
1800 => 'ABC',
9904 => 'DEF',
2003 => 'GHI')
);
$smarty->assign('mySelect', 9904);
SMARTY CODE
{html_options name=foo options=$myOptions selected=$mySelect}
DESIRED HTML OUTPUT
<select name="foo">
<option value="1800" title="ABC">ABC</option>
<option value="9904" title="DEF" selected>DEF</option>
<option value="2003" title="GHI">GHI</option>
</select>
You can't; not with the default html_options function at least. You can try to modify it or better create your own plugin to allow more parameters or complex arrays, but other than that, the best way to do it is generating the list of options in the template using a foreach.
Another option would be to use javascript to add the title attribute to each <option> for this or all selects once the page has been loaded.
By doing <?php $this->load->helper('date'); echo timezone_menu('UM8'); ?> I can get a bunch
of helpful timezone options in a select box from CI which generated as:
<select name="timezones">
<option value="UM12">(UTC -12:00) Baker/Howland Island</option>
<option value="UM11">(UTC -11:00) Samoa Time Zone, Niue</option>
...
</select>
However, I want to add a class (for example, <select name="timezones" class="form-control">) to that select box to inherit style from Bootstrap3. Anyone knows how to do this?
The second parameter sets the class(es) for the select element.
timezone_menu('UM8', 'form-control');
This is covered in the CI Date Helper documentation
I'm building a site that hosts stories that have multiple chapters and on my view I would like the user to be able to select from a drop down menu and go to the chapter they have selected.
I have the drop down populating with information from the database, I'm just having trouble calling another controller based on that selection.
In my view this is my drop down
<select>
<?foreach($chapter as $row) :?>
<option value="<?=$row->chapter_title?>"><?=$row->chapter_title?></option>
<?endforeach;?>
</select>
I did try and add a link to the controller in the option, but that didn't work.
<select>
<?foreach($chapter as $row) :?>
<option value="<?=$row->chapter_title?>">
<?=anchor('story/viewChapter/'.$row->chapter_id, $row->chapter_title);?>
</option>
<?endforeach;?>
</select>
Is there any other way I can do this that does not involve javascript?
Unfortunately, you will have to use javascript:
If your using jquery you could try something like this:
$('#select_id').change(function(){
var chapter = $(this).val();
$(location).attr('href','http://www.mysite.com/books?chapter='+chapter);
});
Here is an example:
http://jsbin.com/efidar/1/
How to write Ajax code to retrieve information on to a particular part of webpage when we select option from a dropdown box?
I want information of a particular item that I had selected from a dropdown menu on particular part of my webpage.
Let's say your markup looks something like:
<select id="dropdown">
<option value="1">Some option</option>
<option value="2">Other option</option>
<option value="3">Helpfull option</option>
<option value="4">Don't pick this option</option>
</select>
<div id="details"></div>
In order to make AJAX calls I would use some sort of library. Using for instance jQuery will be much easier than writing code that handles ajax calls across different browsers. The code could look like this:
$('#dropdown').on('change', function(e) {
var currentValue = $('#dropdown').val();
$.get('<someurl>', function(data) {
$('#details').html(data);
});
};
Replace '<someurl>' with the url to the resource you want. Doing this without using jQuery or similar library is a bit more involved. For some guidance you can look at this answer: https://stackoverflow.com/a/2557268/355499
I`ve trouble on have a HTML document after onchange function by Nokogiri.
Of course, Mechanize lib can control that. but, sadly webpage which I want to control is jsp not HTML.
Generated HTML showes as belows :
form method = "post" name = "mysearchform"
<select id = "hall_no" name = "hall_no" onchange = "document.mysearchform.submit()">
<option value="1" selected=""> 1 </option>
<option value="2"> 2 </option>
</select>
/form
I guess I POST some data by some command, but Im newbie to Ruby and I cant find any solution about that.
Is there anybody who`ve know about that?
You can't. Nokogiri is a HTML parser and can not execute javascript. Go for something like Capybara with a driver that supports javascript.
See http://github.com/jnicklas/capybara