Beginner needs help (parseInt). JS/HTML - parseint

I started to learn this coding thing over a week ago and I don't have much experience in it ( as you probably see).
I have no idea what I'm doing, therefore my code doesn't work, For some reason it prints only first 2 answers.
If you could just let me know how to use if...else statements while using parseInt(document.getElementById("speed").value), it would be great.
Thanks in advance.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Penalty</title>
</head>
<body>
<form>
<label>Fine:</label>
<input type="text" id="speed" size="3">
<input type="button" value="Submit" onclick="sSubmit()">
</form>
<p id="answer"></p>
<script type="text/javascript">
function sSubmit() {
var speed = parseInt(document.getElementById("speed").value);
var result;
if (speed <= 60) {
result = " No fine";
}
else if (speed >= 61 || speed <= 71) {
result = "Fine is 100€";
} else if (speed >= 72 || speed <= 75) {
result = "Fine is 170€";
} else if (speed >= 76 || speed <= 80) {
result = "Fine is 200€";
} else {
result = "Day-fine ";
}
document.getElementById("answer").innerHTML = "<p>" + result + "</p>";
}
</script>
</body>
</html>

You probably should be using && (which means and), not || (which means or).
With your current code, one of the first two options are always going to be run because if the speed is greater than 60 (and thus makes it to the first else if), then it is always going to be either greater than 60 or less than 72. You want it to be greater than 60 and less than 72.
An updated example:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Penalty</title>
</head>
<body>
<form>
<label>Fine:</label>
<input type="text" id="speed" size="3">
<input type="button" value="Submit" onclick="sSubmit()">
</form>
<p id="answer"></p>
<script type="text/javascript">
function sSubmit () {
var speed = parseInt(document.getElementById("speed").value);
var result;
if (speed <= 60){
result = " No fine" ;
}
else if (speed >= 61 && speed <=71 ) {
result = "Fine is 100€" ;
} else if (speed >= 72 && speed <=75 ) {
result = "Fine is 170€" ;
} else if (speed >= 76 && speed <=80 ) {
result = "Fine is 200€" ;
} else {
result = "Day-fine ";
}
document.getElementById("answer").innerHTML= "<p>" + result + "</p>";
}
</script>
</body>
</html>
Also, as a side note, you really shouldn't need the && at all. Since you're working with else if statements, you can simply use <= by itself. In the speed >= 61 && speed <= 71 branch, for example, we know that the speed cannot be less than or equal to 60. If it were, then the previous if body would have been executed, and the else if statement would never have been evaluated. Thus the following JavaScript should suffice:
function sSubmit () {
var speed = parseInt(document.getElementById("speed").value);
var result;
if (speed <= 60){
result = " No fine" ;
}
else if (speed <=71 ) {
result = "Fine is 100€" ;
} else if (speed <=75 ) {
result = "Fine is 170€" ;
} else if (speed <=80 ) {
result = "Fine is 200€" ;
} else {
result = "Day-fine ";
}
document.getElementById("answer").innerHTML= "<p>" + result + "</p>";
}

you dont need to add >= in subsequent else ifs since it reaches there only when the above condition is false
even if you somehow needed to add that it should have been connected with && or else for all the value >=61 will be trapped inside 2nd else if and thus would never reach the blocks below it
i think following is what you are trying to achieve
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Penalty</title>
</head>
<body>
<form>
<label>Fine:</label>
<input type="text" id="speed" size="3">
<input type="button" value="Submit" onclick="sSubmit()">
</form>
<p id="answer"></p>
<script type="text/javascript">
function sSubmit() {
var speed = parseInt(document.getElementById("speed").value);
var result;
if (speed <= 60) {
result = " No fine";
} else if (speed <= 71) {
result = "Fine is 100€";
} else if (speed <= 75) {
result = "Fine is 170€";
} else if (speed <= 80) {
result = "Fine is 200€";
} else {
result = "Day-fine ";
}
document.getElementById("answer").innerHTML = "<p>" + result + "</p>";
}
</script>
</body>
</html>

Related

Showing dialog by Dialog API disables cell editing

In my Excel Add-In, I use the Dialog API to show messages to the user. The dialog is shown and closed without any problem or error thrown.
When the dialog is closed, the user cannot edit cells in the sheet by a simple click in the cell and writing.
If the user double click some cell, this functionality is back again (for all cells).
Here is the code controlling the dialog:
var app = (function (app) {
var dialog;
// Show dialog
app.showNotification = function (header, text) {
if (Office.context.requirements.isSetSupported('DialogApi', 1.1)) {
var dialogUrl = window.location.href.substring(0,
window.location.href.lastIndexOf('/') + 1) +
"AppMessage.html?msg=" + text + "&title=" + header;
Office.context.ui.displayDialogAsync(dialogUrl, {
height: 20,
width: 20,
displayInIframe: true
},
function (asyncResult) {
dialog = asyncResult.value;
dialog.addEventHandler(Office.EventType.DialogMessageReceived,
processMessage);
});
}
};
function processMessage(arg) {
if (arg.message == "close")
dialog.close();
}
return app;
})(app || {});
and the dialog code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/Office.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-js/1.4.0/css/fabric.min.css">
<link rel="stylesheet" href="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-js/1.4.0/css/fabric.components.min.css">
<script src="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-js/1.4.0/js/fabric.min.js"></script>
</head>
<body>
<span class="ms-font-xl ms-fontWeight-semibold" id="titleMain"></span>
<p class="ms-font-m" id="body"></p>
<button class="ms-Button ms-Button--primary" style="position:fixed;bottom:10px;right:10px;" onclick="closeDialog();">
<span class="ms-Button-label">OK</span>
</button>
<script src="appMessage.js"></script>
</body>
</html>
and here is the appMessage.js content
var urlParams;
Office.initialize = function () {};
//avoiding the usage of jquery in this small page
window.$ = function (selector) {
return document.querySelector(selector);
};
function closeDialog() {
Office.context.ui.messageParent("close");
}
(window.onpopstate = function () {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) {
return decodeURIComponent(s.replace(pl, " "));
},
query = window.location.search.substring(1);
urlParams = {};
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
$("#titleMain").innerHTML = urlParams["title"];
$("#body").innerHTML = urlParams["msg"];
})();
What can be wrong?
Thanks

PhoneGap 3.3.0 / Cordova iOS 7 Audio Record Permission

I am new to PhoneGap / Cordova development. Recently there was an update on iOS, and it requires users to grant permission to applications before they can use the microphone.
I had tried to update the "package" - Media and Media Capture, but it still not working.
I've also tried a plugin called cordova-phonegap-audio-encode, but it isn't working too.
The following are my code:
Record.html (This is a page / interface for users to interact and trigger the permission/recording audio)
<html>
<head>
<title>System</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="../js/cordova-2.3.0.js"></script>
<script src="../js/config.js"></script>
<script src="../js/languages.js"></script>
<script src="beJS.js"></script>
<link rel="stylesheet" href="../js/jquery.mobile-1.3.0.min.css" />
<script src="../js/jquery-1.8.2.min.js"></script>
<script src="../js/jquery.mobile-1.3.0.min.js"></script>
<script scr="../js/RecordPermission.js"></script>
</head>
<body >
<div data-role="page" id="beRecordPage">
<div data-role="header" data-theme="c" data-position="fixed">
<a href="index.html" id="btnMenu" target="_self" data-icon="home" data-ajax='false'></a>
<h1 id="be_header_record"></h1>
</div><!-- /header -->
<div data-role="content" >
<div class="content-primary" id='programContent' >
<label for="length" id="be_reocrd_lbl_scriptName"></label>
<input type="text" name='scriptName' id="scriptName" value="" data-clear-btn="true" maxlength="30"/>
<hr/>
<div data-role="controlgroup" >
<button type="button" data-theme="c" id="be_reocrd_btn_record" onclick='record();'></button>
<button type="button" data-theme="c" id="be_reocrd_btn_play" onclick='playRecord();'></button>
<button type="button" data-theme="c" id="be_reocrd_btn_delete" onclick='deleteRecord();'></button>
</div>
<div><!-- /content-primary -->
<div><!-- /content -->
</div><!-- /page -->
<script>
var isRecorded = false;
var isRecording = false;
var isPlaying = false;
var recordResult =false;
var lastSrc = "";
var src = "";
var mediaRec;
function playRecord(){
if(isRecorded && !isRecording){
if(isPlaying){
stopPlaying();
}else{
mediaRec = new Media(lastSrc, stopPlaying,null);
mediaRec.play();
isPlaying = true;
$('#be_reocrd_btn_record').button('disable');
$('#be_reocrd_btn_delete').button('disable');
$('#be_reocrd_btn_play').text(language[langCode].be_reocrd_btn_stop);
$('#be_reocrd_btn_play').button('refresh');
}
}else{
alert(language[langCode].be_reocrd_msg_pleaseRecord);
}
}
function deleteRecord(){
if(isRecorded && !isRecording && !isPlaying){
var confirmation=confirm(language[langCode].be_reocrd_msg_deleteConfirmation);
if(confirmation){
performDeleteRecord()
}
}else{
alert(language[langCode].be_reocrd_msg_deleteError);
}
}
var fileRoot;
function onFileSystemSuccess(fileSystem) {
fileRoot = fileSystem.root;
fileRoot.getFile(lastSrc, {create: false}, onGetFileSuccess, onError);
}
function onGetFileSuccess(entry){
entry.remove(function() {
var idx = --localStorage.SYS_RECORDFILEINDEX;
localStorage.removeItem("SYS_RECORD_NAME"+idx);
localStorage.removeItem("SYS_RECORD_PATH"+idx);
alert(language[langCode].be_reocrd_msg_deleteSuccessful);
}, onError
);
}
function onError() {
alert(language[langCode].be_reocrd_msg_deleteFailure);
}
function onRequestFileSystemSuccess(fileSystem) {
src = fileSystem.root.fullPath + '/' + src;
fileSystem.root.getFile(src, {create: true}, function() {
mediaRec = new Media(src, successRecord,failRecord);
mediaRec.startRecord();
}, function(err) {
alert(err.message);
}
);
/*
var entry=fileSystem.root;
entry.getDirectory(recordFileFolder, {create: true, exclusive: false}, onGetDirectorySuccess, onGetDirectoryFail);
*/
}
function onGetDirectorySuccess(dir) {
alert("Created dir "+dir.name);
mediaRec = new Media(src, successRecord,failRecord);
mediaRec.startRecord();
}
function onGetDirectoryFail(error) {
alert("Error creating directory "+error.code);
}
function performDeleteRecord(){
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onError);
return true;
}
function successRecord(){
isRecorded = true;
recordResult = true;
lastSrc = src;
var idx = localStorage.SYS_RECORDFILEINDEX;
localStorage["SYS_RECORD_NAME"+idx] = $('#scriptName').attr('value');
localStorage["SYS_RECORD_PATH"+idx] = lastSrc;
localStorage.SYS_RECORDFILEINDEX++;
}
function stopPlaying(){
if(mediaRec != null){
mediaRec.stop();
mediaRec = null;
}
isPlaying = false;
$('#be_reocrd_btn_record').button('enable');
$('#be_reocrd_btn_delete').button('enable');
$('#be_reocrd_btn_play').text(language[langCode].be_reocrd_btn_play);
$('#be_reocrd_btn_play').button('refresh');
}
function failRecord(err){
alert(err.message);
alert(language[langCode].be_reocrd_msg_recordFailure);
$('#be_reocrd_btn_record').text(language[langCode].be_reocrd_btn_start);
recordResult = false;
}
function performRecord(){
var result = false;
src = recordFileFolder+new Date().getTime()+".wav";
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onRequestFileSystemSuccess, null);
// mediaRec = new Media(src, successRecord,failRecord);
// mediaRec.startRecord();
}
function record(){
if($('#scriptName').attr('value') == ''){
alert(language[langCode].be_reocrd_msg_pleaseInputName);
return;
}
if(!isPlaying){
if(!isRecording){
$('#be_reocrd_btn_record').text(language[langCode].be_reocrd_btn_stop);
$('#be_reocrd_btn_play').button('disable');
$('#be_reocrd_btn_delete').button('disable');
isRecording = true;
performRecord();
}else{
mediaRec.stopRecord();
isRecording = false;
$('#be_reocrd_btn_record').text(language[langCode].be_reocrd_btn_start);
$('#be_reocrd_btn_play').button('enable');
$('#be_reocrd_btn_delete').button('enable');
}
$('#be_reocrd_btn_record').button('refresh');
}else{
alert(language[langCode].be_reocrd_msg_pleaseStopPlaying);
}
}
$('#beRecordPage').live('pagecreate',function(event){
checkLoggedIn();
$('#be_header_record').text(language[langCode].be_header_record);
$('#btnMenu').text(language[langCode].menu);
$('#be_reocrd_lbl_scriptName').text(language[langCode].be_reocrd_lbl_scriptName);
$('#be_reocrd_btn_record').text(language[langCode].be_reocrd_btn_start);
$('#be_reocrd_btn_play').text(language[langCode].be_reocrd_btn_play);
$('#be_reocrd_btn_delete').text(language[langCode].be_reocrd_btn_delete);
});
</script>
</body>
</html>
This is the RecordPermission.js
window.recordPermission = function(params) {
cordova.exec(function(answer){
if (answer === "True") params.success(true);
else if (answer === "False") params.success(false);
else params.error('success called with "'+answer+'". Must be "True" or "False" strings');
}, params.error,"RecordPermission", "recordPermission");
};
The following is RecordPermission.m
#import "RecordPermission.h"
#implementation RecordPermission
#synthesize callbackId;
- (void)recordPermission:(CDVInvokedUrlCommand*)command
{
self.callbackId = command.callbackId;
// First check to see if we are in ios 7.
NSArray *vComp = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:#"."];
if ([[vComp objectAtIndex:0] intValue] < 7) {
// before iOS7 when this permission was not required or setable by the user
[self performSelectorOnMainThread:#selector(doSuccessCallback:) withObject:#"True" waitUntilDone:NO];
} else {
// run this in a try just in case
#try {
[[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
// cast this to a string bc I don't know if you can or how to pass a boolean back to javascript.
// This is converted back to a javascript boolean in RecordPermission.h.js file
NSString * grantedString = (granted) ? #"True" : #"False";
// talking back to javascript must be done in main thread.
[self performSelectorOnMainThread:#selector(doSuccessCallback:) withObject:grantedString waitUntilDone:NO];
}];
} #catch (id exception) {
NSLog(#"recordPermission try error");
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_JSON_EXCEPTION messageAsString:[exception reason]];
NSString* javaScript = [pluginResult toErrorCallbackString:command.callbackId];
[self writeJavascript:javaScript];
}
}
}
-(void) doSuccessCallback:(NSString*)granted {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:granted];
NSString* javaScript = [pluginResult toSuccessCallbackString:self.callbackId];
[self writeJavascript:javaScript];
}
#end
This is the RecordPermission.h
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import <Cordova/CDV.h>
#interface RecordPermission : CDVPlugin{
NSString* callbackId;
}
#property (nonatomic, retain) NSString* callbackId;
- (void)recordPermission:(NSArray*)arguments ;
#end
So far I cannot trigger the permission and I checked "Settings" where the app does not appear at the "Microphone" page.
Please help! Thank you.

Given a polygon in latitude and longitude and a set of points, determine which points lie inside

Given a set of latlon points that make up a polygon, and a set of latlon points, how can I determine which points lie inside. The polygon may be up to 100km across and the error could be a few hundred meters (i.e. points inside or outside can fail or be included incorrectly at the edges). The polygons and points won't be near the poles. Can I treat the latlon points as 2d, or do I need to convert them to a projection of some kind? Circles are easy but I wonder if the error will be too great for a 100km wide polygon?
I plan to do this in C++ but the language doesn't matter.
Here is the (javascript) code from Openlayers to do it
/**
* Method: containsPoint
* Test if a point is inside a polygon. Points on a polygon edge are
* considered inside.
*
* Parameters:
* point - {<OpenLayers.Geometry.Point>}
*
* Returns:
* {Boolean | Number} The point is inside the polygon. Returns 1 if the
* point is on an edge. Returns boolean otherwise.
*/
containsPoint: function(point) {
var numRings = this.components.length;
var contained = false;
if(numRings > 0) {
// check exterior ring - 1 means on edge, boolean otherwise
contained = this.components[0].containsPoint(point);
if(contained !== 1) {
if(contained && numRings > 1) {
// check interior rings
var hole;
for(var i=1; i<numRings; ++i) {
hole = this.components[i].containsPoint(point);
if(hole) {
if(hole === 1) {
// on edge
contained = 1;
} else {
// in hole
contained = false;
}
break;
}
}
}
}
}
return contained;
}
Complete file can be found at Openlayers at Github
To get the idea behind this.components have a look at Collection.js
update:
In OpenLayers a polygon is a collection of linear rings. the containsPoint functon of this can be found at LinearRing.js
You can view actual demo here
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>How to Check If Point Exist in a Polygon - Google Maps API v3</title>
<script type="text/javascript" src="http://www.the-di-lab.com/polygon/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script type="text/javascript">
var map;
var boundaryPolygon;
function initialize() {
var mapProp = {
center: new google.maps.LatLng(26.038586842564317, 75.06787185438634),
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map-canvas"), mapProp);
google.maps.Polygon.prototype.Contains = function (point) {
// ray casting alogrithm http://rosettacode.org/wiki/Ray-casting_algorithm
var crossings = 0,
path = this.getPath();
// for each edge
for (var i = 0; i < path.getLength() ; i++) {
var a = path.getAt(i),
j = i + 1;
if (j >= path.getLength()) {
j = 0;
}
var b = path.getAt(j);
if (rayCrossesSegment(point, a, b)) {
crossings++;
}
}
// odd number of crossings?
return (crossings % 2 == 1);
function rayCrossesSegment(point, a, b) {
var px = point.lng(),
py = point.lat(),
ax = a.lng(),
ay = a.lat(),
bx = b.lng(),
by = b.lat();
if (ay > by) {
ax = b.lng();
ay = b.lat();
bx = a.lng();
by = a.lat();
}
if (py == ay || py == by) py += 0.00000001;
if ((py > by || py < ay) || (px > Math.max(ax, bx))) return false;
if (px < Math.min(ax, bx)) return true;
var red = (ax != bx) ? ((by - ay) / (bx - ax)) : Infinity;
var blue = (ax != px) ? ((py - ay) / (px - ax)) : Infinity;
return (blue >= red);
}
};
google.maps.event.addListener(map, 'click', function (event) {
if (boundaryPolygon != null && boundaryPolygon.Contains(event.latLng)) {
alert("in")
document.getElementById("spnMsg").innerText = "This location is " + event.latLng + " inside the polygon.";
} else {
alert("out")
document.getElementById("spnMsg").innerText = "This location is " + event.latLng + " outside the polygon.";
}
});
}
function drawPolygon() {
initialize();
var boundary = '77.702866 28.987153, 77.699776 28.978594 ,77.735996 28.974164 ,77.719946 28.99346 ,77.713423 28.994361 ,77.711706 28.990382 ';
var boundarydata = new Array();
var latlongs = boundary.split(",");
for (var i = 0; i < latlongs.length; i++) {
latlong = latlongs[i].trim().split(" ");
boundarydata[i] = new google.maps.LatLng(latlong[1], latlong[0]);
}
boundaryPolygon = new google.maps.Polygon({
path: boundarydata,
strokeColor: "#0000FF",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: 'Red',
fillOpacity: 0.4
});
google.maps.event.addListener(boundaryPolygon, 'click', function (event) {
document.getElementById("spnMsg").innerText = '';
if (boundaryPolygon.Contains(event.latLng)) {
document.getElementById("spnMsg").innerText = "This location is " + event.latLng + " inside the polygon.";
} else {
document.getElementById("spnMsg").innerText = "This location is " + event.latLng + " outside the polygon.";
}
});
map.setZoom(14);
map.setCenter(boundarydata[0]);
boundaryPolygon.setMap(map);
}
</script>
</head>
<body onload="initialize();drawPolygon();">
<form id="form1" runat="server">
<h3>Check If Point Exist in a Polygon</h3>
<h3>click on the polygon and out side the polygon for testing</h3>
<span id="spnMsg" style="font-family: Arial; text-align: center; font-size: 14px; color: red;">this is message</span>
<br />
<br />
<div id="map-canvas" style="width: auto; height: 500px;">
</div>
</form>
</body>
</html>
you can view more demos may be use full to you here
http://codeace.in/download/gmap/
you can download all the demo
by click on the file
"googlemap.zip" given in the index

Can't autoclick icon link within a frame for a webpage VBA

I'm trying to write a vba code to autoclick icon link after logged in. I'm stuck with the vba code I wrote below and when I run the vba macro no responses. I believe the icon link is within a frame for a webpage. Please help thanks
I've tried right clicking on the icon link to check for the frame url address, and navigate to that webpage once logged in however it automatically redirects to another page which I don't want.
URL address (target webpage with the icon link): "https://trading.poems.com.hk/poems2/poems.asp?func=view"
Auto Redirected webpage: "https://trading.poems.com.hk/poems2/loginaction.asp"
The icon link html code:
<img src="images/Corner/EN/Company.png" border=0 title="Stock Analytics ">
My VBA code:
Sub open3()
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate "https://trading.poems.com.hk/poems2/poems.asp?func=view"
Do Until ie.readyState = 4
DoEvents
Loop
For Each ele In ie.document.getElementsByTagName("a")
If InStr(ele.innerHTML, "images/Corner/EN/Company.png") > 0 Then
ele.Click
Exit For
End If
Next
End Sub
The frames of the webpage:
<html>
<head>
<title>Phillip Securities (HK)-?????? (?????????)</title>
<link rel="shortcut icon" href="images/phillip.ico">
<meta http-equiv="Content-Type" content="text/html; charset=big5"></head>
<frameset cols="*, 100%" border=0 frameborder=0 framespacing=0 marginheight=0 marginwidth=0>
<frame src="Poems2/BrowserChecking.asp" name="ChkBrowser">
<frame src="Poems2/Poems.asp" name="login" frameborder=0 framespacing=0 marginheight=0 marginwidth=0>
</frameset><noframes></noframes>
</html>
Parts of the HTML source code:
<!DOCTYPE html PUBLIC "-/W3C//DTD XHTML 1.0 Transtitional//EN"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5" />
<title>??????-?????????</title>
</head>
<link href="css/phillip.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" >document.domain="poems.com.hk"</script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/ddsmoothmenu_Execution_EN.css" />
<script type='text/javascript' src='js/ddsmoothmenu.js'></script>
<script type="text/javascript" src="js/font.js"></script>
<script type="text/javascript">
ddsmoothmenu.init({
mainmenuid: "smoothmenu1", //menu DIV id
orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
classname: 'ddsmoothmenu', //class added to menu's outer DIV
//customtheme: ["#1c5a80", "#18374a"],
contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})
</script>
<script type="text/javascript">
var myclose = false;
function ConfirmClose()
{
frameURL = (parent.DetailFrame.location.href).toUpperCase()
//alert(frameURL + "//// " + frameURL.indexOf("PPSHK.COM"))
if (frameURL.indexOf("PPSHK") > 0)
{
if (event.clientY < 0)
{
event.returnValue = '???????????, ?????????\n????!';
//setTimeout('myclose=false',10000);
//myclose=true;
}
}
}
function parentExists() {
return (parent.location == window.location) ? false : true;
}
if(!parentExists())
document.location = "../index2.htm"
function checkKeyCode(evt)
{
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if(event.keyCode==116)
{
location.reload(true);
return false
}
}
document.onkeydown=checkKeyCode;
</script>
<body onUnload="CloseAllPop()">
<script>
var EFuturePop
var StockPop
var USStockPop
var SGStockPop
var JPStockPop
var SAStockPop
var SOptionPop
var SNOptionPop
var StockGTCPop
var BullionPop
var FxBannerPop
var FoFuturePop
var ForexPop
var FoOptionsPop
var ForexResponse
var FoFutureResponse
var FoOptionsResponse
function CloseAllPop(){
if(EFuturePop != null){
EFuturePop.close()
}
if(StockPop != null){
StockPop.close()
}
if(USStockPop != null){
USStockPop.close()
}
if(SGStockPop != null){
SGStockPop.close()
}
if(JPStockPop != null){
JPStockPop.close()
}
if(SAStockPop != null){
SAStockPop.close()
}
if(SOptionPop != null){
SOptionPop.close()
}
if(SNOptionPop != null){
SNOptionPop.close()
}
if(StockGTCPop != null){
StockGTCPop.close()
}
if(BullionPop != null){
BullionPop.close()
}
// if(FxBannerPop != null){
// FxBannerPop.close()
// }
if(FoFuturePop != null){
FoFuturePop.close()
}
if(ForexPop != null){
ForexPop.close()
}
if (FoOptionsPop != null) {
FoOptionsPop.close()
}
}
function forexClose(ans){
ForexResponse = ans;
}
function foFutureClose(ans){
FoFutureResponse = ans;
}
function foOptionsClose(ans) {
FoOptionsResponse = ans;
}
function DisclaimerClose(type,ans){
if (type == "Forex"){
ForexResponse = ans;
}
else if (type == "FoFuture"){
FoFutureResponse = ans;
}
else if (type == "FoOptions") {
FoOptionsResponse = ans;
}
}
function changeDetailFrame(link) {
$('#DetailFrame').attr('src',link);
}
function CheckStockGTCPop(){
if(StockGTCPop != null){
parent.DetailFrame.location.href = "NoPopup/ZH/TradeStock_GTC.asp"
}
else{
StockGTCPop = window.open('StockDisclaimer_GTC.asp','HKStockGTC','scrollbars=yes,resizable=yes,status=no,left=0,top=0,width=1014,height=710,toolbar=0')
}
}
function CheckForexPop(){
if (ForexResponse=="A"){
if (ForexPop.closed) {
ForexPop = window.open('Forex/asp/menu/100kforex_fr.asp','Forex','scrollbars=yes,resizable=yes,status=no,left=0,top=0,width=1014,height=710,toolbar=0')
}
}
else{
ForexPop = window.open('ForexDisclaimer.asp','Forex','scrollbars=yes,resizable=yes,status=no,left=0,top=0,width=1014,height=710,toolbar=0')
}
}
function CheckFoFuturePop(){
if (FoFutureResponse=="A"){
if (FoFuturePop.closed){
FoFuturePop = window.open('FoFutures/EN/ftslingshot2b3/LiveMain_fr.asp?type=F', 'FoFuture', 'scrollbars=yes,resizable=yes,status=no,left=0,top=0,width=1014,height=710,toolbar=0')
}
}
else{
FoFuturePop = window.open('FoFutureDisclaimer.asp','FoFuture','scrollbars=yes,resizable=yes,status=no,left=0,top=0,width=1014,height=710,toolbar=0')
}
}
function CheckFoOptionsPop() {
if (FoOptionsResponse == "A") {
if (FoOptionsPop.closed) {
FoOptionsPop = window.open('FoFutures/EN/ftslingshot2b3/LiveMain_fr.asp?type=O', 'FoFuture', 'scrollbars=yes,resizable=yes,status=no,left=0,top=0,width=1014,height=710,toolbar=0')
}
}
else {
FoOptionsPop = window.open('FoOptionsDisclaimer.asp','FoOptions', 'scrollbars=yes,resizable=yes,status=no,left=0,top=0,width=1014,height=710,toolbar=0')
}
}
// function CheckFoFuturePop_FO(){
// FoFuturePop = window.open('FoFutures/EN/ftslingshot2b3/LiveMain_fr_FO.asp','FoFuture','scrollbars=yes,resizable=yes,status=no,left=0,top=0,width=1014,height=710,toolbar=0')
// }
function CheckFxBannerPop(){
if(FxBannerPop != null){
parent.DetailFrame.location.href = "Forex/asp/menu/100kforex_fr.asp"
}
else{
parent.DetailFrame.location.href = "Forex/asp/menu/100kforex_fr.asp"
FxBannerPop = window.open('Banner.htm','FxBanner','scrollbars=yes,resizable=yes,status=no,left=0,top=0,width=600,height=300,toolbar=0')
}
}
//document.body.onunload = CloseAllPop
</script>
<table width="985" border="0" align="center" cellpadding="0" cellspacing="0" id="maintable">
<tr>
<td width="10" background="images/bgsquareleft.jpg"></td>
<td bgcolor="#FFFFFF"><table width="940" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="64"><img src="POEMSBanner.gif" alt="Phillip's ON-LINE ELECTRONIC MART SYSTEM" height="54" border="0" /></td>
<td align="right" valign="bottom" class="style3">
<img src="images/Corner/EN/tradingcen.png" border=0 title="Trading Central">
<img src="images/Corner/EN/Company.png" border=0 title="Stock Analytics ">&>
Your URL "https://trading.poems.com.hk/poems2/poems.asp?func=view" returns HTML code for a frameset page with not a single tag.
Note that the Document element within the Browser object doesn't expand the underlying pages. You see the same here as you would in the browser using the "show source" function
Check the possibility of calling (one of) the framed page(s) directly

How to make a Sharepoint Survey window open on page load

I've been working on looking for an answer to this issue for several days. I've created a survey on a Sharepoint 2010 site, and the person who I made it for wants it to open in a modal window on page load, instead of having to click "Respond to Survey" for this to happen.
I've tried multiple javascript based solutions, and so far I've gotten nothing. Is there any way to do this? And, if there is, is it possible that this solution could be ported to other pages, so that I can make other surveys or other sharepoint pages open in a modal window (on page load) instead of on a separate page?
Use .../yoursite/lists/yoursurvey/NewForm.aspx - It seems the Advanced setting "use open forms in dialog" doesn't work.
I have made this for a policy window. I made the whole thing inside of a content editor webpart which basically in invisible because the code has no appearence and I set the chrome type to none.
The other option is a feature which would replace the masterpage which is also not hard but requires a developement system for VS2010.
For the first method mentioned. You may have to strip the cookie stuff if you want it to load every time.
Create a new Content Editor Web Part with this:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="disclaimer.js"></script>
Then create disclaimer.js:
_spBodyOnLoadFunctionNames.push("initialDisclaimerSetup");
var dialogTitle = "";
var dialogBody = "";
var dialogReturn = "";
var userID = _spUserId;
function initialDisclaimerSetup() {
if(getCookie("DisclaimerShown" + userID) == "Yes") {
return;
} else {
setCookie("DisclaimerShown" + userID, "No", 365);
}
getDisclaimerListItems();
}
function setCookie(cookieName, cookieValue, numExpireDays) {
var expirationDate = new Date();
expirationDate.setDate(expirationDate.getDate() + numExpireDays);
document.cookie = cookieName + "=" + cookieValue + ";" +
"expires=" + ((numExpireDays == null) ? "" : expirationDate.toUTCString());
}
function getCookie(cookieName) {
if(document.cookie.length > 0) {
return document.cookie.split(";")[0].split("=")[1];
} else {
return "";
}
}
function getDisclaimerListItems() {
var listName = "Disclaimer";
var soapEnv = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+ "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
+ "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope\/\">"
+ "<soap:Body>"
+ "<GetListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">"
+ "<listName>" + listName + "</listName>"
+ "<query><Query><Where><IsNotNull><FieldRef Name=\"Title\" /></IsNotNull></Where></Query></query>"
+ "<ViewFields><ViewFields>"
+ "<FieldRef Name=\"Title\"/><FieldRef Name=\"Disclaimer\"/>"
+ "</ViewFields></ViewFields>"
+ "</GetListItems>"
+ "</soap:Body>"
+ "</soap:Envelope>";
$.ajax({
url: "_vti_bin/Lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
contentType: "text/xml; charset=\"utf-8\"",
complete: processResult
});
}
function processResult(xData, status) {
$(xData.responseXML).find("z\\:row").each(function() {
dialogTitle = $(this).attr("ows_Title");
dialogBody = $(this).attr("ows_Disclaimer");
launchModelessDialog();
if(dialogReturn == 0) {
return false;
} else if(dialogReturn == 1) {
} else if(dialogReturn == 2) {
return false;
}
});
if(dialogReturn == 0) {
getDisclaimerListItems();
} else if(dialogReturn == 1) {
setCookie("DisclaimerShown" + userID, "Yes", 365);
} else if(dialogReturn == 2) {
window.close();
}
}
function GetRootUrl() {
var urlParts = document.location.pathname.split("/");
urlParts[urlParts.length - 1] = "";
return "https://" + document.location.hostname + urlParts.join("/");
}
function launchModelessDialog(){
if (window.showModalDialog) {
window.showModalDialog("./disclaimer.htm", window, "dialogWidth:700px;dialogHeight:700px");
} else {
objPopup = window.open("./disclaimer.htm", "popup1", "left=100,top=100,width=800,height=800,location=no,status=yes,scrollbars=yes,resizable=yes, modal=yes");
objPopup.focus();
}
}
Then create disclaimer.htm:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<script type="text/javascript">
function initialRun() {
//var allArgs = dialogArguments;
var dialogTitle = dialogArguments.dialogTitle;
var dialogBody = dialogArguments.dialogBody;
dialogArguments.dialogReturn = "0";
document.getElementById('mainWrapper').innerHTML = "<h1>" + dialogTitle + "</h1>"
+ "<br/>" + dialogBody + "<br/><br/>";
}
function returnYes() {
dialogArguments.dialogReturn = 1;
window.close();
}
function returnNo() {
dialogArguments.dialogReturn = 0;
window.close();
}
function returnClose() {
dialogArguments.dialogReturn = 2;
window.close();
}
</script>
</head>
<body onload="initialRun()">
<div id="mainWrapper">
</div>
<div align="center">
<input name="acceptTOS" type="button" value="I Accept" onClick="returnYes();" />
<input name="acceptTOS" type="button" value="I Do NOT Accept" onClick="returnNo();" />
<input name="acceptTOS" type="button" value="Close" onClick="returnClose();" />
</div>
</body>
</html>
Then create a new Custom List called 'Disclaimer' and add a new column called 'Disclaimer' which allows for free text.

Resources