Ionic and Arduino communication via Bluetooth - javascript

// Ionic Starter LLc
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snLLcing when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
var LLc = {
intialize: function() {
this.bind();
},
bind: function(){
document.addEventListener('deviceready', this.deviceready, true);
},
//the device is ready for use
deviceready: function() {
Auto.checked = LLc.Cycle;
Note.checked = LLc.Notifications;
// throttle changes
var throttledCChange = _.throttle(LLc.CChange, 200);
$('input').on('change', throttledCChange);
},
//handles the color changes done by the sliders
CChange: function (evt) {
var c = LLc.ColorChange();
LLc.ArduinoPush(c);
},
//creates an array to hold all the slider values into, that will be fed to arduino
ColorChange: function(){
var color = [];
color.push(red.value);
color.push(green.value);
color.push(blue.value);
return color.join(',');
},
ArduinoPush: function (c){
bluetoothSerial.write("c" + c + "\n");
},
//color cycle mode for arduino
Cycle: function(){
red.value = 0;
green.value = 0;
blue.value = 0;
while(Auto.checked == true){
while(red.value < 250){
if(blue.value > 0 ){blue.value = blue.value - 25;}
red.value = red.value + 25;
var c = LLc.getColor();
LLc.ArduinoPush(c)
}
while(green.value < 250){
green.value = green.value + 25;
red.value = red.value - 25;
var c = LLc.getColor();
LLc.ArduinoPush(c)
}
while(blue.value < 250){
blue.value = blue.value + 25;
green.value = green.value - 25;
var c = LLc.getColor();.
LLc.ArduinoPush(c)
}
}
},
Notifications: function(){
},
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<html ng-app="ionicApp">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/topcoat-mobile-dark.min.css">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!--ng-cordova Script -->
<script src="js/ng-cordova.min.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="Starter" ng-controller="MainCtrl">
<ion-pane>
<ion-header-bar class="bar-dark">
<h1 class="topcoat-navigation-bar">
<div class="topcoat-navigation-bar__item center full">
<h1 class="topcoat-navigation-bar__title">LovellLight Companion</h1>
</div>
</h1>
</ion-header-bar>
<ion-content>
<li class="item item-toggle">
AutoMode
<label class="toggle toggle-calm">
<input type="checkbox" id="Auto">
<div class="track">
<div class="handle">
</div>
</div>
</label>
</li>
<li class="item item-toggle">
Notification Mode
<label class="toggle toggle-assertive">
<input type="checkbox" id="Note">
<div class="track">
<div class="handle">
</div>
</div>
</label>
</li>
<div class="list">
<div class="item range range-positive">
<div class= "positive"> Blue </div>
<input type="range" name="blue" id="blue" min="0" max="250" value="0">
<i class="icon ion-plus-circled"></i>
</div>
<div class="item range range-assertive">
<div class= "assertive"> Red </div>
<input type="range" name="red" id="red" min="0" max="250" value="0">
<i class="icon ion-plus-circled"></i>
</div>
<div class="item range range-balanced">
<div class= "balanced"> Green </div>
<input type="range" name="green" id="green" min="0" max="250" value="0">
<i class="icon ion-plus-circled"></i>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</ion-content>
</ion-pane>
</body>
</html>
Hello All! I'm new to Ionic app development and had a few question on how to get started, or moreso how to get my app and my Arduino trading information. I am trying to make a simple app to be able to change the color of a light on a adafruit ring light connected to the Arduino. Problem is, I have be unsuccessful in being able to get them to speak.
Because I want to make this app as simple as possible, I have followed the PhoneGap tutorial for light changes as far as actually changing color and sending data to the Arduino is concered, but have been unable to get any reliable feedback to the Arduino, or any feedback whatsoever. this is especially concerning, since I have the bluetooths connected using a different app, but still connected nonetheless. I scoured the interwebs for many differen tutorials, learning about the different parts I used in my code while also learning that there's a lot more to app development that I anticipated.
Anybody out there can help? I'd much appreciate some advice.
Ionic code attached.

Related

KO "click" binding won't work for mobile device responsive

I am trying to create a responsive one page web application. On clicking the list of items on the side bar you the markers and on the map should animate and display info window. It seems to be working perfect on normal browser layout but when I toggle display to smaller screens or on a mobile device, The click function does not work. The logic seems to be correct. Please help me understand where I am going wrong and what I should do. Thank you.
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link href="style.css" rel="stylesheet">
<script src="js/jquery-3.2.1.js"></script>
<script src="js/knockout-3.4.0.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div id="sidebar" class="col-xs-12 col-sm-5 col-md-3">
<h1 class="center" > Chennai City Culture </h1>
<div class="input-group col-xs-12 col-sm-6 col-md-12" >
<input id="text-search" type="text" class="form-control" placeholder="Enter here" data-bind="textInput: query">
</div>
<div class= "list-box" data-bind="foreach: filteredItems">
<hr>
</div>
</div>
<div class="col-xs-16 col-sm-6 col-md-8">
<div id="map">
</div>
</div>
</div>
</div>
<script src="js/app.js"></script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBf9eFadPLrD3QIQT7ygrYN8aRO5YuAUyE&callback=initMap" onerror="error()">
</script>
</body>
</html>
JS:
function appViewModel(){
var self = this;
this.query = ko.observable('');
this.locationArray = ko.observableArray([]);
locations.forEach(function(item){
self.locationArray().push(item);
});
self.setLoc = function(clickedLoc) {
var clickedData = clickedLoc.marker;
google.maps.event.trigger(clickedData, 'click');
};
self.filteredItems = ko.computed(function(){
var filter = self.query().toLowerCase();
if(!filter){
for (i = 0; i < locations.length; i++) {
if (locations[i].marker) //checks to see that markers exist
locations[i].marker.setVisible(true);
}
return self.locationArray();
}
return this.locationArray().filter(function (item){
var passedFilter = item.title.toLowerCase().indexOf(filter) > -1;
item.marker.setVisible(passedFilter);
return passedFilter;
});
}, self);
}
ko.applyBindings(new appViewModel());
click events aren't the same as touch events; try including a library like touchpunch that will handle those events for you for mobile devices. I had the same issue with a KO app I was building and that seemed to solve it.

Printing Multiple Labels from PHP/Web Application to Dymo LabelWriter 450 Turbo

I'm looking to add the functionality to print multiple labels using a Dymo LabelWriter 450 Turbo. I've downloaded the DYMO-Label-v.8-SDK.dmg from the Dymo site but can't see any Javascript/web related SDK files or documentation - all I can see are AppleScript examples which won't help here.
Does anyone know if this is possible (data for labels will come from backend database connected to PHP web app). I can't find any documentation for a Javascript SDK on the Dymo Developer website - only some examples from a few years ago so not even sure what is the current state and which is the latest version etc and whether there is a way to print multiple labels?
I actually just built this functionality in my own web app using the exact same printer and I'm feeling friendly today. Here is what I have working for me in a production level application. Good luck!
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>DYMO: QR-code</title>
<!-- JQuery -->
<script src = "http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript" charset="UTF-8"> </script>
<!-- Dymo Script -->
<script src="DYMO.Label.Framework.2.0.2.js" type="text/javascript" charset="UTF-8"></script>
<!-- QR Code -->
<script src="QRCode.js" type="text/javascript" charset="UTF-8"> </script>
<!-- Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<div class="jumbotron">
<h3>DYMO Label Framework JavaScript Library Samples: QR code</h3>
<div class="header">
<div id="sampleDesctiption">
<span>
This sample shows different ways to print a label with a QR-code barcode.
</span>
</div>
</div>
</div>
<div class="container">
<div class="printControls">
<div class="row">
<div class="col-md-6">
<div id="printersDiv">
<label for="printersSelect">Printer:</label><br/>
<select class="form-control" id="printersSelect"></select>
</div>
</div>
</div>
<div id="printDiv" style="padding-top:20px">
<button class="btn btn-primary btn-lg" id="printButton">Print QR Code</button>
</div>
</div>
</div>
</div>
</body>
</html>
QRCode.js
// stores loaded label info
var barcodeLabel;
// called when the document loaded
function onload() {
var printersSelect = document.getElementById('printersSelect');
var printButton = document.getElementById('printButton');
// loads all supported printers into a combo box
function loadPrinters() {
var printers = dymo.label.framework.getLabelWriterPrinters();
if (printers.length == 0) {
alert("No DYMO printers are installed. Install DYMO printers.");
return;
}
console.log("got here: ", printers );
for (var i = 0; i < printers.length; i++) {
var printer = printers[i];
var printerName = printer.name;
var option = document.createElement('option');
option.value = printerName;
option.appendChild(document.createTextNode(printerName));
printersSelect.appendChild(option);
}
}
printButton.onclick = function () {
var label_text = 'QRCode Text Here..';
barcodeLabel.setObjectText('Barcode', label_text);
// Should Be Printer Name, Dymo 450 Turbo..
console.log("print: ", printersSelect.value );
barcodeLabel.print( printersSelect.value );
}
function getBarcodeLabelXml() {
var labelXml = '<?xml version="1.0" encoding="utf-8"?>\
<DieCutLabel Version="8.0" Units="twips">\
<PaperOrientation>Landscape</PaperOrientation>\
<Id>Address</Id>\
<PaperName>30252 Address</PaperName>\
<DrawCommands>\
<RoundRectangle X="0" Y="0" Width="1581" Height="5040" Rx="270" Ry="270" />\
</DrawCommands>\
<ObjectInfo>\
<BarcodeObject>\
<Name>Barcode</Name>\
<ForeColor Alpha="255" Red="0" Green="0" Blue="0" />\
<BackColor Alpha="0" Red="255" Green="255" Blue="255" />\
<LinkedObjectName></LinkedObjectName>\
<Rotation>Rotation0</Rotation>\
<IsMirrored>False</IsMirrored>\
<IsVariable>False</IsVariable>\
<Text></Text>\
<Type>QRCode</Type>\
<Size>Small</Size>\
<TextPosition>None</TextPosition>\
<TextFont Family="Arial" Size="8" Bold="False" Italic="False" Underline="False" Strikeout="False" />\
<CheckSumFont Family="Arial" Size="8" Bold="False" Italic="False" Underline="False" Strikeout="False" />\
<TextEmbedding>None</TextEmbedding>\
<ECLevel>0</ECLevel>\
<HorizontalAlignment>Center</HorizontalAlignment>\
<QuietZonesPadding Left="0" Top="300" Right="600" Bottom="0" />\
</BarcodeObject>\
<Bounds X="331" Y="57.9999999999999" Width="2880" Height="1435" />\
</ObjectInfo>\
</DieCutLabel>';
return labelXml;
}
function loadLabelFromWeb() {
barcodeLabel = dymo.label.framework.openLabelXml( getBarcodeLabelXml() );
}
// Load Labels
loadLabelFromWeb();
// load printers list on startup
loadPrinters();
};
// Run's Dymo Javascript..
dymo.label.framework.init(onload);

Can't handle input "change" event or value after document load

I have two inputs on my form whose value I would like to change when the document has loaded.
This is my code:
<?php
$base = dirname(dirname(__FILE__));
include($base."/include/db.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>eMail Stationery | Installation for iPhone/iPad</title>
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../font-awesome/css/font-awesome.css" rel="stylesheet">
<link href="../css/plugins/steps/jquery.steps.2.css" rel="stylesheet">
<link href="../css/animate.css" rel="stylesheet">
<link href="../css/style.css" rel="stylesheet">
</head>
<body class="gray-bg">
<div class="">
<center>
<img src="../img/esignia.png">
<h3>iPhone/iPad Installation</h3>
<p>Follow the steps provided to install your signature</p>
</center>
</div>
<div id="wizard">
<h3>Enter your details</h3>
<section>
<center>
<div class="row"></div>
<p><h2>Enter your details</h2></p>
<p>Enter your email address and unique pin number into the fields below to receive an email with a link to your signature.</p>
<div class="row">
<div class="col-lg-4"></div>
<div class="col-lg-4">
<form id="submitForm" method="post">
<center>
<div class="form-group">
<input id="email" name="email" type="email" placeholder="Email address" class="form-control" required>
</div>
<div class="form-group">
<input id="pin" name="pin" type="number" placeholder="Unique PIN" class="form-control" required>
</div>
<button class="btn btn-success">Submit</button>
<p>
</p>
</center>
</form>
</div>
</div>
</center>
</section>
<h3>Copying your signature</h3>
<section>
<center>
<p><h2>Copying your signature</h2></p>
<p>Once you have followed the link we provided in the email, you will see your signature displayed fully on your device's web browser.</p>
<p>Simply highlight all of your signature and copy it to your device's clipboard as demonstrated below.</p>
<p><img src="../img/install/iphone_2.png" width="320px" height="480px"></p>
</center>
</section>
<h3>Locating your signature settings</h3>
<section>
<center>
<p><h2>Locating your signature settings</h2></p>
<p>Great! We've copied your signature and it is now ready to be installed!</p>
<p>We just need to find your mail's signature settings.</p>
<p>These are located at <b>Settings -> Mail, Contacts, Calendars -> Signature</b>
<p><img src="../img/install/iphone_3.png" width="320px" height="480px">
<img src="../img/install/iphone_4.png" width="320px" height="480px"></p>
</center>
</section>
<h3>Installing your signature</h3>
<section>
<center>
<p><h2>Installing your signature</h2></p>
<p>Now that we have your signature settings open, you'll find an empty box ready for your signature to be pasted.</p>
<p>So all you need to do now is paste what we copied earlier into the box.</p>
<p><img src="../img/install/iphone_5.png" width="320px" height="480px"></p>
<p>One final thing you'll need to do is give your phone a quick shake to undo any of the modifications that your device will attempt to make to your signature's HTML code.</p>
<p>This is necessary for your signature to appear <i>exactly</i> how it appeared when you opened it.</p>
<p><img src="../img/install/iphone.gif"></p>
<p class="text-navy"><b>Congratulations, you've now successfully installed your signature to your device!</b></p>
</center>
</section>
</div>
</div>
</div>
<!-- Mainly scripts -->
<script src="../js/jquery-2.1.1.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/plugins/steps/jquery.steps.js"></script>
<script>
$(document).ready(function() {
var email = getUrlParameter("email");
var pin = getUrlParameter("pin");
if(email != undefined && pin != undefined) {
$("#email").val(email);
$("#pin").val(pin);
}
$("#wizard").steps({
headerTag: "h3",
bodyTag: "section",
transitionEffect: "slideLeft",
autoFocus: true
});
$("#submitForm").submit(function() {
var email = $("input[name='email']").val();
var pin = $("input[name='pin']").val();
$.get("../api/installed.php", {
email: email,
pin: pin
});
});
$("a[href='#finish'").click(function() {
window.location.href = "index.php";
});
});
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};
</script>
</body>
</html>
This does not work.
However, I replicate the same code in chrome's console and it works perfectly. My only assumption is that these controls are being messed with and/or recreated with Bootstrap/jQuery after the document has been loaded.
But I can't figure out where or why, or what I should do.
This might because of DOM not ready, try using below code
$(window).load(function() {
var email = getUrlParameter("email");
var pin = getUrlParameter("pin");
if(email != undefined && pin != undefined) {
$("#email").val(email);
$("#pin").val(pin);
}
}
If still not work try to change your Ids of element to check weather its conflict with other element or not

How to stop reload of page after submit

I have a page with a form that is being used to ask a question. When the submit button is clicked, it does the follow, determines if the user checked the right box, displays the answer and explanation, and disables the checkboxes and submit button to prevent re-answering the question.
My issue is that when the user clicks the submit button the answers, and the disabling appear for only a split second before the page reloads. How do I stop this, I want the user to see if they are correct and not be able to change their answers. When I run it in Dreamweaver where I am building the pages, it runs fine in live view.
Code is below:
<!-- Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"
rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css"
rel="stylesheet" />
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<link href="../styles/casestyles.css" rel="stylesheet" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" language="javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script type="text/javascript">
</script>
<!-- show all on submit and show checked answer -->
<script type="text/javascript" src="../js/submit_answers.js"> </script>
<!-- Add jQuery library -->
<script type="text/javascript" src="fancybox/lib/jquery-1.10.1.min.js"></script>
<!-- Add mousewheel plugin (this is optional) -->
<script type="text/javascript" src="fancybox/lib/jquery.mousewheel-3.0.6.pack.js"></script>
<!-- Add fancyBox main JS and CSS files -->
<script type="text/javascript" src="fancybox/source/jquery.fancybox.js?v=2.1.5"></script>
<link rel="stylesheet" type="text/css" href="fancybox/source/jquery.fancybox.css?v=2.1.5" media="screen" />
<!-- Add Button helper (this is optional) -->
<link rel="stylesheet" type="text/css" href="fancybox/source/helpers/jquery.fancybox-buttons.css?v=1.0.5" />
<script type="text/javascript" src="fancybox/source/helpers/jquery.fancybox-buttons.js?v=1.0.5"></script>
<script type="text/javascript" src="../js/fancybox.js"></script>
<script type="text/javascript">
/***********************************************
* Limit number of checked checkboxes script- by JavaScript Kit (www.javascriptkit.com)
* This notice must stay intact for usage
* Visit JavaScript Kit at http://www.javascriptkit.com/ for this script and 100s more
***********************************************/
function checkboxlimit(checkgroup, limit){
var checkgroup=checkgroup
var limit=limit
for (var i=0; i<checkgroup.length; i++){
checkgroup[i].onclick=function(){
var checkedcount=0
for (var i=0; i<checkgroup.length; i++)
checkedcount+=(checkgroup[i].checked)? 1 : 0
if (checkedcount>limit){
alert("You can only select a maximum of "+limit+" diagnosis")
this.checked=false
}
}
}
}
</script>
<!-- disable checkboxes -->
<script type="text/javascript">
function disablefields(){
{
document.getElementById('check1').disabled='disabled';
document.getElementById('check2').disabled='disabled';
document.getElementById('check3').disabled='disabled';
document.getElementById('check4').disabled='disabled';
document.getElementById('ex3').disabled='disabled';
document.getElementById('ex3').value='Answers Submitted'; }
}
</script>
</head>
<script type="text/javascript">
function myfunction(){
//call disable checkbox
disabled(document);
//call disable submit
checkForm(form) ;
}
</script>
.explanation {
display: none;
}
.correct {
display:none;
}
.incorrect {
display:none;
}.explanation {
display: none;
}
.correct {
display:none;
}
.incorrect {
display:none;
}
<div class="row-offcanvas row-offcanvas-left">
<div id="sidebar" class="sidebar-offcanvas">
<div class="col-md-12">
<ul class="nav nav-pills nav-stacked">
<li>History of Present Illness </li>
<li>Review of Systems </li>
<li>Past Medical History </li>
<li>Physical Examination </li>
<li>Essential Differential Diagnosis</li>
<li>Relevant Testing</li>
<li>Diagnosis</li>
<li>Treatment</li>
<li>Questions</li>
<li>About the Case</li>
</ul>
</div>
</div>
<form name="limit" onreset="disablefields();" onSubmit="disablefields();" >
<div id="main" class="container-fluid">
<div class="col-md-12">
<p class="visible-xs">
<button type="button" class="btn btn-primary btn-xs" data-toggle="offcanvas"> <i class="glyphicon glyphicon-chevron-left"></i> </button>
</p>
<!-- Footer Code -->
<div id="footer" style="overflow-y:hidden; overflow-x:hidden;">
<div class="container" style="overflow-y:hidden; overflow-x:hidden;">
<p class="muted credit"><img src="img/prev.png" width="24" height="21" / > <a href="relevant_testing.html" > Relevant Testing </a> | <a href="treatment.html" > Treatment </a><img src="img/next.png" width="24" height="21" />
</div>
</div>
<!-- Change the Heading -->
<h3>Diagnosis</h3>
<h5>At this time, the most likely diagnosis is</h5>
<p>Please choose only one.</p>
<!-- First Column-->
<div class="col-md-3">
<div class="bootstrap-demo">
<!-- content goes here -->
<p style="margin-bottom:0px">
<input id="check1" name="field" type="checkbox" value="incorrect" />
Acute bronchitis</p>
<div class="correct" style="margin-left:20px;"><font color="#008000">Correct</font></div>
<div class="incorrect" style="margin-left:20px;"><font color="#FF0000">Incorrect</font></div>
<div class="explanation" style="margin-left:20px;">Although the patient has a productive cough, he also has an infiltrate on chest x-ray.</div>
<p style="margin-bottom:0px">
<input id="check2" name="field" type="checkbox" value="correct" />
Community-acquired pneumonia</p>
<div class="correct" style="margin-left:20px;"><font color="#008000">Correct</font></div>
<div class="incorrect" style="margin-left:20px;"><font color="#FF0000">Incorrect</font></div>
<div class="explanation" style="margin-left:20px;">The chest x-ray shows a definite infiltrate.</div>
<p style="margin-bottom:0px">
<input id="check3" name="field" type="checkbox" value="incorrect" />
Health-care associated pneumonia</p>
<div class="correct" style="margin-left:20px;"><font color="#008000">Correct</font></div>
<div class="incorrect" style="margin-left:20px;"><font color="#FF0000">Incorrect</font></div>
<div class="explanation" style="margin-left:20px;">The patient was not a resident in a nursing home or other long-term care facility.</div>
<p style="margin-bottom:0px">
<input id="check4" name="field" type="checkbox" value="incorrect" />
Lung cancer</p>
<div class="correct" style="margin-left:20px;"><font color="#008000">Correct</font></div>
<div class="incorrect" style="margin-left:20px;"><font color="#FF0000">Incorrect</font></div>
<div class="explanation" style="margin-left:20px;">Although an obstructing cancer may cause an infiltrate, it is not the most likely cause of this patient’s acute symptoms.</div>
<p> <br />
<input type="submit" value="Submit" id="ex3" onclick="show_all();" >
</p>
</div>
</div>
<!-- Second Column -->
<div class="col-md-3">
<div class="bootstrap-demo">
<!-- content goes here -->
<p>Click <a class="fancybox fancybox.iframe" href="relevant_testing_all.html">here</a> to see the tests and explanations for this diagnosis</p>
</div>
</div>
<div class="col-md-3"> <img src="../img/patient-001.png" width="231" height="184" alt="Patient 001" /></div>
</div>
</div>
</form>
</div>
<!-- Bootstrap script -->
<script type="text/javascript" language="javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../lightbox/js/lightbox.min.js"></script>
<link href="../lightbox/css/lightbox.css" rel="stylesheet" type="text/css" />
<script type='text/javascript'>
$(document).ready(function() {
$('[data-toggle=offcanvas]').click(function() {
$('.row-offcanvas').toggleClass('active');
});
});
</script>
<script type="text/javascript">
var one="";
var two="";
function check(browser)
{
//document.getElementById("answer").value = browser
one = browser
updateIt()
}
function check1(browser)
{
//document.getElementById("answer").value += " " + browser
two = browser
updateIt()
}
function updateIt()
{
document.getElementById("answer").value = one +" "+ two
}
</script>
<!--Script to call limit checkbox code-->
<script type="text/javascript">
//Syntax: checkboxlimit(checkbox_reference, limit)
checkboxlimit(document.forms.limit.field, 1)
</script>
As of right now your code is not "determining if the user checked the right box, displaying the answer and explanation" as you explained but that is OK and easy to implement after. Here is the answer to your question.
You should replace your id="ex3" button with the anchor tag code provided below (anchor tag is for simplicity but you can use another element to call the function with a click event). Either way, you do not need to submit a form as you are not posting information according to your requested behavior.
<a id="ex3" href="javascript:disablefields()">submit</a>
Update your function with this:
function disablefields() {
{
document.getElementById('check1').disabled = 'disabled';
document.getElementById('check2').disabled = 'disabled';
document.getElementById('check3').disabled = 'disabled';
document.getElementById('check4').disabled = 'disabled';
document.getElementById('ex3').disabled = 'disabled';
document.getElementById('ex3').innerHTML = 'Answers Submitted';
}
}
You will then get the exact behavior requested in your question minus the validation process that you described. It is easy to add that to this solution with a conditional statement or calling a validation function and then if valid calling the disablefields function.
function formVal() {
{
//put all of your validation requirements here and see if
var isValid = [check form function here]
if(isValid){
disablefields();
}else {
//send a message to user to correct fields and do not disable
}
<a id="ex3" href="javascript:formVal()">submit</a>
If you do choose to submit the information to the server at some later date simply make an AJAX call sending the form information after your disablefields call.
Fixed it by calling both function from the onClick and changing the type to button.
<input type="button" value="Submit" id="ex3" onclick="show_all(); disablefields();" >

Popovers in Twitter Bootstrap

Okay, so I have the following HTML code:
<!DOCTYPE html>
<html>
<head>
<title>FastCast</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/footer.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
<link rel="shortcut icon" href="favicon1.ico"/>
</head>
<body>
<center>
<h1><b>Welcome to FastCast!</b></h1>
<div>
<p><font size="3">FastCast is a web application designed to gather weather information from various sources and display it in an easy-to-read format.</font></p>
<hr></hr>
<div id="picDiv">
<img id="imgDisp" src="logo.jpg">
</div>
<p><font size="6">Enter you location to get started.</font></p>
</div>
<form class="form-inline" role="form">
<div class="form-group">
<input type="text" class="form-control" id="Location" placeholder="ex. Boston, MA">
</div>
</form>
<p><i>Press enter to continue.</i></p>
<a id="test">Click me</a>
<script>
window.onkeydown = function(event) {
if (event.keyCode === 13) {
var x = document.getElementById("Location").value;
var last2 = x.slice(-2);
alert(last2);
}
}
var i = 0;
$('a#test').click(function() {
i += 1;
$('a#test').popover({
trigger: 'manual',
placement: 'right',
content: function() {
var message = last2;
return message;
}
});
$('a#test').popover("show");
});
</script>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://code.jquery.com/jquery.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</center>
</body>
<div class="footer" id="footer">Developed in Twitter Bootstrap | Information from openweathermap.org | Tyler Jablonski, 2014+</div>
</html>
Towards the end I have a link that says "Click me". As you can see, in the script tags that follow, I have a bit of code that looks like this:
var i = 0;
$('a#test').click(function() {
i += 1;
$('a#test').popover({
trigger: 'manual',
placement: 'right',
content: function() {
var message = last2;
return message;
}
});
$('a#test').popover("show");
});
I was hoping that this code would active a popover when the link is clicked, but for some reason, it doesn't work. Nothing happens at all. Why is this, and how can I properly make a popover in Bootstrap and then have it display a JavaScript variable?
Thanks!
You are missing some things in your popover element <a> tag, have the format be something like this:
<a id="test" data-toggle="tooltip" rel="popover">Click Me</a>
Then it should work, for example: http://jsfiddle.net/52VtD/1983/

Categories