Choose Selected Option on Page Load of Razor Html DropDownListFor

Samual Sam
Updated on 04-Mar-2020 06:13:12

188 Views

Shorthand is used to decide which option is selected on pageload of razor Html.DropDownListFor(). You can try to run the following code snippet −// return Boolean value @Html.DropDownListFor(m => m.Valeur, new List< SelectListItem > { //new list item list item1 is generated new SelectListItem { Value = "0" , Text = "Show", Selected = Model.Valeur == 0 }, new SelectListItem { Value = "1" , Text = "Hide", Selected = Model.Valeur != 0 }, }, new { @class = “selectnew" })

Materialize CSS Checkbox with Html CheckBoxFor

Ankith Reddy
Updated on 04-Mar-2020 06:08:57

212 Views

The only way to materialize CSS checkbox to work with Html.checkbox without disappearance of the checkbox to the left is by moving the hidden element to the bottom of the parent element.$("input[type='hidden']").each(checkbox1 (0,IsActive ) {    $(this).appendTo($(IsActive).parent()); });In this hidden element, IsActive is placed in the bottom of parent element thus removing the disappearance of the checkbox to left and thus materializing CSS checkbox to work with HTML.checkbox.

Stream Video File to HTML5 Video Player with Node.js

Prabhas
Updated on 04-Mar-2020 05:25:44

295 Views

Use createReadStream to send the requested part to the client. The function call createReadStream() will give you a readable stream. ExampleThe following is the code −stream = fs.createReadStream(path); stream.on('open', function () {    res.writeHead(206,{       "Content-Range":"bytes " + begin + "-" + end + "/" +total, "Accept-Ranges":"bytes",          "Content-Length":chunksize, "Content-Type":"new/mp4"    });    stream.pipe(res); });

Draw Image from Data URL to HTML5 Canvas

Arjun Thakur
Updated on 04-Mar-2020 05:06:54

1K+ Views

If you have a data url, you can create an image to a canvas. This can be done as shown in the following code snippet −var myImg = new Image; myImg.src = strDataURI;The drawImage() method draws an image, canvas, or video onto the canvas. The drawImage() method can also draw parts of an image, and/or increase/reduce the image size.The code given below is also appropriate with the sequence - create the image, set the onload to use the new image, and then set the src −// load image from data url Var Obj = new Image(); Obj.onload = function() { ... Read More

Properly Use H1 in HTML5

varun
Updated on 04-Mar-2020 05:06:02

262 Views

 h1 is a heading and not a title. Youcan gives own heading element to each sectioning element. h1 cannot be the title. It can be the heading of that particular section of the page. Each article can have its own title. defines the most important heading. The first element is considered the label for the entire document. It is perfectly fine to use as many tags as your document calls for; that is one per sectioning root or content section. Use one set of tags per sectioning root or content section. There should always be an ... Read More

Change Text Color Based on Background Brightness in HTML

usharani
Updated on 04-Mar-2020 05:03:50

303 Views

It is possible to change the textcolour depending on the average brightness of the covered pixels ofits parent's background color by using the following code snippet.var rgb = [255, 0, 0]; setInterval(display, 1000); function display() {    rgb[0] = Math.round(Math.random() * 255);    rgb[1] = Math.round(Math.random() * 255);    rgb[2] = Math.round(Math.random() * 255);        var d = Math.round(((parseInt(rgb[0]) * 299) + (parseInt(rgb[1]) * 587) +       (parseInt(rgb[2]) * 114)) / 1000);    // for foregound    var f = (d> 125) ? 'black' : 'white';       // for background   var b = 'rgb(' + rgb[0] + ',' + rgb[1] + ',' + rgb[2] + ')';   $('#box').css('color', f);   $('#box').css('background-color', b); } DemoThe following is the CSS −#box {    width: 300px;   height: 300px; }

Bootstrap Dropdown Closing When Clicked in HTML

usharani
Updated on 04-Mar-2020 05:03:11

2K+ Views

As you may have seen, whenever you open a dropdown, and click anywhere else, the dropdown close. By using the below given code, the dropdown menu can be kept open after click−$('#myDropdown').on('hide.bs.dropdown', function () {    return false; });Another option is to handle the clickevent −The click event can also be handled byusing the following code. The event.stopPropagation() method stopsthe bubbling of an event to parent elements. It prevents any parentevent handlers from being executed −$('#myDropdown .dropdown-menu').on({    "click":function(e) {        e.stopPropagation();     } });

Client Checking File Size Using HTML5

Arjun Thakur
Updated on 04-Mar-2020 05:02:06

435 Views

Before HTML5, the file size was checked with flash but now flash is avoided in web apps. Still the file size on the client side can be checked by inserting the below given code inside an event listener.if (typeofFileReader !== "undefined") {    // file[0] is file 1    var s = document.getElementById('myfile').files[0].size; }On file input change, the size will update. For that, use event listener,document.getElementById('input').onchange = function() {    // file[0] is file 1    var s = document.getElementById('input').files[0].size;    alert(s); }

Check If Audio is Playing in HTML5

mkotla
Updated on 04-Mar-2020 04:59:44

5K+ Views

Use the following to check if audio is playing −functionisPlaying(audelem) {    return!audelem.paused; }The above code can be used to check ifaudio is playing or not. The audio tag has a paused property.The paused property returns whether the audio/video is paused.You can also toggle −functiontogglePause() {    if(newAudio.paused && newAudio.currentTime > 0 && !newAudio.ended) {       newAudio.play();    } else {       newAudio.pause();    } }

HTML5 File Uploads with AJAX and jQuery

Arjun Thakur
Updated on 04-Mar-2020 04:58:53

680 Views

When the form is submitted, catch the submission process and try to run the following code snippet for file upload −// File 1 var myFile = document.getElementById('fileBox').files[0]; var reader = new FileReader(); reader.readAsText(file, 'UTF-8'); reader.onload = myFunc; function myFunc(event) {    var res = event.target.result; var fileName = document.getElementById('fileBox').files[0].name;    $.post('/myscript.php', { data: res, name: fileName }, continueSubmission); }Then, on the server side (i.e. myscript.php) −$data = $_POST['data']; $fileName = $_POST['name']; $myServerFile = time().$fileName; // Prevent overwriting $fp = fopen('/uploads/'.$myServerFile, 'w'); fwrite($fp, $data); fclose($fp); $retData = array( "myServerFile" => $myServerFile ); echo json_encode($retData);Read More

Advertisements