I created a show entries box but I don't know how to link it to the data table so it renders the number that is selected. I am doing this to fix the location of the box by using css and js, reading their documents wasn't very helpful to me. thank you.
this is my select box code:
I tried:
.pageLength
.lengthMenu
.plengthMenu in the script
<div class="fixedd" style="color: azure">
Show Entries: <select name="showentries" type="select"
id="showentries" placeholder="Search...." style=" color: black">
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
</div>
and this is my script:
$(document).ready(function () {
var dataTable = $('#scrape').dataTable({
"pageLength": 100,
"bLengthChange": false,
});
$("#searchbox").keyup(function () {
dataTable.fnFilter(this.value);
});
$("#showentries").keyup(function () {
datatable.lengthMenu(this.value);
});
});
by the way the search box works fine.
This is what i did to make it work. However it works only on IE if anyone has an idea on how to make it work on chrome feel free to comment or add answer.
<div class=" fixedd" style="color: azure">
Show Entries: <select name="showentries" type="select" id="showentries" placeholder="Search...." style="color: black">
<option id="_10" value="10">10</option>
<option id="_25" value="25">25</option>
<option id="_50" value="50">50</option>
<option id="_100" value="100">100</option>
</select>
</div>
<script>
$(document).ready(function () {
var dataTable = $('#scrape').dataTable({
// "pageLength": 100,
"bLengthChange": false,
fixedHeader: {
header: true,
footer: true,
headerOffset: 50
},
});
var table = $('#scrape').DataTable();
$("#searchbox").keyup(function () {
dataTable.fnFilter(this.value);
});
//'.btn-details',
$("#scrape").on('click', function () {
table.page.len(10).draw();
});
$("#scrape").on('click', function () {
table.page.len(25).draw();
});
$("#scrape").on('click', function () {
table.page.len(50).draw();
});
$("#scrape").on('click', function () {
table.page.len(100).draw();
});
});
</script>
Related
I am trying to put a select in my application with Angular 7 and Materialize. However, this item is not displayed in the browser.
In the documentation and in some Stackoverflow posts it says that I must initialize the component with the following script:
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('select');
var instances = M.FormSelect.init(elems, options);
});
// Or with jQuery
$(document).ready(function(){
$('select').formSelect();
});
// Or
$(document).ready(function () {
$('select').material_select();
});
But it still doesn't work for me
angular.json
"styles": [
"./node_modules/material-icons/iconfont/material-icons.css",
"./node_modules/materialize-css/dist/css/materialize.min.css",
"src/styles.scss"
],
"scripts": [
"./node_modules/jquery/dist/jquery.min.js",
"./node_modules/materialize-css/dist/js/materialize.min.js"
]
component.html
<div class="row">
<select>
<option value="1">Cuenta 1</option>
<option value="2">Cuenta 2</option>
</select>
</div>
<script>
$(document).ready(function(){
$('select').formSelect();
});
</script>
Can someone help me please?
Thank you
The solution is to initialize the select only when it is already showing
Here is my .ts
import * as M from 'materialize-css';
setTimeout(() => {
M.FormSelect.init(document.querySelectorAll('mySelect'), {});
}, 30);
And my .html
<div class="row">
<select id="mySelect">
<option value="1">Cuenta 1</option>
<option value="2">Cuenta 2</option>
</select>
</div>
I have created a dropdownlist that is using pop up link, but I want to change it to open in a new tab function because some of the browser such as safari that will not notify user this is the pop up link that make user think this dropdownlist is not a function at all so I want to change it, any suggestion or changing my code? Thanks
<div class="classddown2">
<select name="class-schedule-dropdown2" id="class-schedule-dropdown2" style="width: 1100px; color: #000000;">
<option style='color: #000000'selected="selected" disabled="disabled">Select Class Schedule</option>
<option style='color: #000000'value="http://www.example.com">example 1</option>
</select>
<script type="text/javascript">
var urlmenu = document.getElementById( 'class-schedule-dropdown2' );
urlmenu.onchange = function() {
window.open( this.options[ this.selectedIndex ].value );
};
</script></div>
Adding '_blank' as parameter for the option method should open your link in a new Tab:
window.open( this.options[ this.selectedIndex ].value, '_blank');
So your code would be this:
<div class="classddown2">
<select name="class-schedule-dropdown2" id="class-schedule-dropdown2" style="width: 1100px; color: #000000;">
<option style='color: #000000'selected="selected" disabled="disabled">Select Class Schedule</option>
<option style='color: #000000'value="http://www.example.com">example 1</option>
</select>
<script type="text/javascript">
var urlmenu = document.getElementById( 'class-schedule-dropdown2' );
urlmenu.onchange = function() {
window.open( this.options[ this.selectedIndex ].value, '_blank');
};
</script>
</div>
Or add the script directly to your select tag:
<select onchange="window.open(this.options[this.selectedIndex].value,'_blank')" name="class-schedule-dropdown2" id="class-schedule-dropdown2" style="width: 1100px; color: #000000;">
I'm currently working on a project where I have a button that adds a dropdown everytime you click on the button.
Clicking the button not only shows the dropdown, but also a "Remove item" button, where you can remove the respective item added.
Then if you select an option from the dropdown, it will show another dropdown with more options, depending on what you chose on the first dropdown.
You can choose from the dropdown two options, movies or games.
And then on the second dropdown should appear a movie list or a game list depending on what you selected.
You can see HERE the current fiddle.
index.html:
<div ng-app="myApp" ng-controller="testCtrl">
<button ng-click = "addNewItem()">Add new Item</button>
<div ng-repeat="item in itemSet.item track by $index">
<button ng-click = "removeItem($index)">Remove item</button>
<select ng-model="category"
ng-change="changeCategory(category)"
ng-options="category as category for category in categoryTypes">
<option></option>
</select>
<select ng-show="movieSelected"
ng-model="movieType"
ng-options="movie as movie for movie in movieCategories">
<option></option>
</select>
<select ng-show="gameSelected"
ng-model="gameType"
ng-options="game as game for game in gameCategories">
<option></option>
</select>
</div>
</div>
app.js:
var myApp = angular.module('myApp', []);
myApp.controller('testCtrl', ['$scope', function ($scope) {
$scope.categoryTypes = ['Movies', 'Games'];
$scope.gameCategories = ['RPG', 'Sports'];
$scope.movieCategories = ['Action', 'SciFi'];
$scope.itemSet = { item : [] };
$scope.itemSet.item = [];
$scope.gameSelected = false;
$scope.movieSelected = false;
$scope.addNewItem = function () {
$scope.itemSet.item.push('');
};
$scope.removeItem = function (index) {
$scope.itemSet.item.splice(index, 1);
};
$scope.changeCategory = function(category) {
if(category == 'Movies') {
$scope.gameSelected = false;
$scope.movieSelected = true;
} else {
$scope.gameSelected = true;
$scope.movieSelected = false;
}
};
}]);
There are some things that are going wrong with this. With no order in particular:
For example, if I added 3 items, and then want to delete the first one, it will delete the third, then the second and finally the first if you keep pressing the "Remove Item" button.
If I add 3 items and I select "movies" from the first dropdown on the first row for example, it will display all of the other dropdowns with the possibility of choosing the items from the movie list on all of them, even if I didn't choose anything from the other rows.
Also if you want to add, lets say, 2 items, in one item you pick first "movies" and then on the second one you pick "games", the "extra" dropdowns will show the list of games instead of the respective list of items for each of the cases.
The actual project works similar to this, but with 4 dropdowns, and the information comes from a database but I guess that with the Fiddle should be enough to get the idea and to take a possible solution to the actual project.
If someone could help me out on this one I'll be very gratefull!
Your code has a big problem that is: you have the same ngModel for all items in ngRepeat.
After fixing this, you can simplify a lot your code.
You don't need to use ngChange to know what category is selected, you can simply use ngSwitch directive what fits well in this case.
See it working:
(function() {
'use strict';
angular
.module('myApp', [])
.controller('testCtrl', testCtrl);
testCtrl.$inject = ['$scope'];
function testCtrl($scope) {
$scope.categoryTypes = ['Movies', 'Games'];
$scope.gameCategories = ['RPG', 'Sports'];
$scope.movieCategories = ['Action', 'SciFi'];
$scope.itemSet = {
item: []
};
$scope.addNewItem = function() {
$scope.itemSet.item.push({});
};
$scope.removeItem = function(index) {
$scope.itemSet.item.splice(index, 1);
};
}
})();
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="testCtrl">
<button ng-click="addNewItem()">Add new Item</button>
<div ng-repeat="item in itemSet.item track by $index">
<button ng-click="removeItem($index)">Remove item</button>
<select ng-model="item.category"
ng-options="category for category in categoryTypes">
<option value hidden>Select a category</option>
</select>
<span ng-switch="item.category">
<select ng-switch-when="Movies"
ng-model="item.movie"
ng-options="movie for movie in movieCategories">
<option value hidden>Select a movie</option>
</select>
<select ng-switch-when="Games"
ng-model="item.game"
ng-options="game for game in gameCategories">
<option value hidden>Select a game</option>
</select>
</span>
</div>
<pre ng-bind="itemSet.item | json"></pre>
</div>
</body>
</html>
The main problem is you're controls are bound $scope values instead of the individual items you are trying to manipulate. A secondary problem is that you initialize each new array element as an empty string '' instead of an object {}.
This will work:
index.html
<div ng-app="myApp" ng-controller="testCtrl">
<button ng-click = "addNewItem()">Add new Item</button>
<div ng-repeat="item in itemSet.item track by $index">
<button ng-click = "removeItem($index)">Remove item</button>
<select ng-model="item.category"
ng-change="changeCategory(item)"
ng-options="category as category for category in categoryTypes">
<option></option>
</select>
<select ng-show="item.movieSelected"
ng-model="movieType"
ng-options="movie as movie for movie in movieCategories">
<option></option>
</select>
<select ng-show="item.gameSelected"
ng-model="gameType"
ng-options="game as game for game in gameCategories">
<option></option>
</select>
</div>
</div>
app.js
var myApp = angular.module('myApp', []);
myApp.controller('testCtrl', ['$scope', function ($scope) {
$scope.categoryTypes = ['Movies', 'Games'];
$scope.gameCategories = ['RPG', 'Sports'];
$scope.movieCategories = ['Action', 'SciFi'];
$scope.itemSet = { item : [] };
$scope.itemSet.item = [];
$scope.gameSelected = false;
$scope.movieSelected = false;
$scope.addNewItem = function () {
$scope.itemSet.item.push({});
};
$scope.removeItem = function (index) {
$scope.itemSet.item.splice(index, 1);
};
$scope.changeCategory = function(item) {
if(item.category == 'Movies') {
item.gameSelected = false;
item.movieSelected = true;
} else {
item.gameSelected = true;
item.movieSelected = false;
}
};
}]);
Updated fiddle:https://jsfiddle.net/5zwsdbr0/
I have an example:
<select id="to_select_list" multiple="multiple" name="to_select_list">
<option value="winder">Winter</option>
<option value="summer">Summer</option>
<option value="rainy">Rainy</option>
<option value="Spring">Spring</option>
</select>
And I want to when I click on submit, all of the option value will be sent to server through "to_select_list" but no need to select (all) those.
Resolve:
I figured out how to solve this problem at the link
Example:
Javascript:
<script language="javascript" type="text/javascript">
var selObj2 = document.getElementById(selStr2);
for (var i = 0; i < selObj2.options.length; i++) {
selObj2.options[i].selected = true;
}
</script>
HTML:
<form action="tutorial007.html" method="get" onsubmit="selectAllOptions('sel2');">
If you don't want users to select which options should be sent, then don't give them a select control. Just use hidden inputs.
<input type="hidden" name="to_select_list" value="winder">
<input type="hidden" name="to_select_list" value="summer">
<input type="hidden" name="to_select_list" value="rainy">
<input type="hidden" name="to_select_list" value="Spring">
Try this with JQuery
var optVals=[];
$("#to_select_list option").each(function(){
optVals.push( $(this).attr('value'));
});
without JQuery you can use this
var option = document.getElementById('to_select_list').options;
and then
var val0 = option[0].value;
also you can send the array to server by AJAX like this
$.ajax({
url: 'your url',
type: 'POST',
data: {optionValues: optVals },
success: function (data) {
},
Error: function () {
}
});
so I've been working on this watching tutorials and such, but ran into a problem and need help. So i have a dropdown list that populates another dropdown list successfully. The problem is that I am creating the 2nd dropdown list to be populated, but want to populate an existing dropdownlist. Could anybody give me any advice on how to do this if I did not create the 2nd dropdown list and already had one(so it would populate the 2nd dropdown list which would already exist)?
Here is what I have:
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<form name="form1" action="submit.php" method='POST'>
<select name="country" onchange="window.getStates()">
<option value="">Select State</option>
<option value="louisiana">Louisiana</option>
<option value="texas">Texas</option>
<option value="alabama">Alabama</option>
<option value="mississippi">Mississippi</option>
</select>
<input type="submit" name="submit" value="Submit">
</form>
<script type="text/javascript">
function getStates()
{
var xmlhttp;
try{
xmlhttp = new XMLHttpRequest;
}catch(e)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if(xmlhttp)
{
var form = document['form1'];
var country = form['country'].value;
xmlhttp.open("GET", "getScools.php?country="+country, true);
xmlhttp.onreadystatechange = function ()
{
if(this.readyState == 4)
{
var s = document.createElement("select");
s.name= "state";
s.innerHTML = this.responseText;
if(form['state'])
{
form.replaceChild(s, form['state']);
}else
form.insertBefore(s, form['submit']);
}
}
xmlhttp.send(null)
}
}
</script>