PhoneGap Calendar Plugin iOS non-responsive - javascript

<div class="jumbotron">
<h1>Set Up Appointment</h1>
<form action="" id="input" method="get" name="input">
document.addEventListener('deviceready', function(){ var cal; cal =
window.plugins.calendarPlugin; $('#submit').click(function() { function
createEvent(title,location,notes, startDate, endDate){ var title =
document.getElementById=("name"); var notes =
document.getElementById=("location"); var startDate =
document.getElementById=("startDate"); var endDate =
document.getElementById=("endDate");
cal.createEvent(title,location,notes,startDate,endDate); } }); },
false);<a href="https://www.nycm.com/Default.asp" target=
"blank"><img src=
"http://www.nycm.com/apcd/images/LogoTitle.gif"></a><br>
<div class="inputTable" style="width:300px">
<table>
<tr>
<td>Name</td>
<td><input id="name" type="text"></td>
</tr>
<tr>
<td>Location</td>
<td><input id="location" type="text"></td>
</tr>
<tr>
<td>Start Date</td>
<td><input id="startDate" type="date"></td>
</tr>
<tr>
<td>End Date</td>
<td><input id="endDate" type="date"></td>
</tr>
<tr>
<td>Additional Info</td>
<td><input id="notes" type="text"></td>
</tr>
</table>
<div class="submitButton">
<input id="submit" type="submit" value="Submit">
</div>
</div><br>
</form>
</div>
It takes in the input but it's not making an event in the native calendar on the phone.
I'm running it through the PhoneGap build on a mac using X code.
I really just need to know how to connect the javascript, using PhoneGap, to the native calendar on the iOS.
Any help would be awesome.

try this one.
make sure you already define your plugin in your config.xml
<feature name="CustomPlugin">
<param name="ios-package" value="CustomPlugin" />
</feature>
Implementing the plug-in by using Objective-C code
CustomPlugin.h
#import <Foundation/Foundation.h>
#import <Cordova/CDV.h>
#interface CustomPlugin : CDVPlugin
- (void)sayHello:(CDVInvokedUrlCommand*)command;
#end
CustomPlugin.m
#import "CustomPlugin.h"
#implementation CustomPlugin
- (void)sayHello:(CDVInvokedUrlCommand*)command{
NSString *responseString =
[NSString stringWithFormat:#"Hello World, %#", [command.arguments objectAtIndex:0]];
CDVPluginResult *pluginResult =
[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:responseString];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
#end
Calling a plug-in from JavaScript
function initial(){
var name = $("#NameInput").val();
cordova.exec(sayHelloSuccess, sayHelloFailure, "CustomPlugin", "sayHello", [name]);
}
function sayHelloSuccess(data){
alert("OK: " + data);
}
function sayHelloFailure(data){
alert("FAIL: " + data);
}

Related

add values in a textarea using a add button & it should be displayed in other textarea appended in a new row

How to add values in a textarea using a add button & that values should be displayed in other textarea using HTML5
<script src="http://code.jquery.com/jquery-1.11.3.min.js">
jQuery('#constraint_btn').click(function(){
var newVal = jQuery('#consEditor_txtarea').attr('value');
jQuery('#new_html').show();
jQuery('#new_consEditor_txtarea').attr('value',newVal);
});
</script>
<table>
<tr>
<td valign="top"><label>Constarint Editor </label></td>
<td><textarea id="consEditor_txtarea"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="button" name="" id="constraint_btn" value="Add Constraint" /></td>
</tr>
<tr id="new_html">
<td><label>Added Constraints </label></td>
<td><textarea id="new_consEditor_txtarea"></textarea></td>
</tr>
</table>
You need to close the script tags with the src and start a new script tag - if there is a src attribute, then you cannot have content inside the script
You need https (and preferably update the jquery to a newer version) in the jQuery source
You did not call the fields the same in the code as in the HTML
You need to execute the code after the page has loaded or the fields rendered - here I wrapped in the $(function() {}) load event handler
#new_html {
display: none;
}
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
$(function() {
$('#constraint_btn').click(function() {
let oldVal = $('#consEditor_txtarea').val().trim();
let newVal = $('#new_consEditor_txtarea').val().trim();
const vals = newVal.split("\n").filter(item => item);
if (oldVal) vals.push(oldVal);
$('#consEditor_txtarea').val(""); // remove
$('#new_html').show();
$('#new_consEditor_txtarea').val(vals.join("\n"));
});
});
</script>
<table>
<tr>
<td valign="top"><label>Constraint Editor </label></td>
<td><textarea id="consEditor_txtarea"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="button" name="" id="constraint_btn" value="Add Constraint" /></td>
</tr>
<tr id="new_html">
<td><label>Added Constraints </label></td>
<td><textarea id="new_consEditor_txtarea"></textarea></td>
</tr>
</table>

"input type="submit"" not displaying as a button

I am trying to create a web-based quiz application where the quiz is inputted through a form and then inputted into a text file. this will then be read from the text file to the user separately. My submit button is not working however, have i laid it out wrong?
The idea is to then read the text file line by line calling on values define by these lines, and displaying the options in radio format on a seperate webpage. Also, i wish to add a new button called "add question" which adds the question and 3 answer input texts to the bottom of the form, making it responsive to the user. Would i have to make the whole form a function and call on it?
function WriteToFile(passForm) {
set fso = CreateObject("Scripting.FileSystemObject");
set s = fso.CreateTextFile(“using theseee / this.txt ", True);
var year = document.getElementById(‘year’);
var class = document.getElementById(‘class’);
var topic = document.getElementById(‘topic’);
var title = document.getElementById(‘title’);
var question = document.getElementById(‘question’);
var option1 = document.getElementById(‘answer1’);
var option2 = document.getElementById(‘answer2’);
var option3 = document.getElementById(‘answer3’);
s.writeline(“Title: " + title);
s.writeline(“Question: " + question);
s.writeline(“Option1: " + answer1);
s.writeline(“Option2: " + answer2);
s.writeline(“Option3: " + answer3);
s.writeline("-----------------------------"); s.Close();
}
<html>
<head>
<title>Quiz Form</title>
<link rel=“stylesheet” href=“TRYstyle.css”>
</head>
<body>
<h3>Quiz form</h3>
<table>
<form onSubmit=“WriteToFile(this.txt)”>
<tr>
<td>Title</td>
<td><input type=“text” placeholder=“Title” name=“title” id=“title” maxlength=“200”/></td>
</tr>
<tr>
<td>Question</td>
<td><input type=“text” placeholder=“Question” name=“question” id=“question” maxlength=“200”/></td>
</tr>
<tr>
<td>Answer</td>
<td><input type=“text” placeholder=“Answer” name=“answer1” id=“answer1” maxlength=“200”/></td>
</tr>
<tr>
<td>Answer</td>
<td><input type=“text” placeholder=“Answer” name=“answer2” id=“answer2” maxlength=“200”/></td>
</tr>
<tr>
<td>Answer</td>
<td><input type=“text” placeholder=“Answer” name=“answer3” id=“answer3” maxlength=“200”/></td>
</tr>
<tr>
<input type=“submit” value=“Submit”>
</tr>
</form>
</table>
</body>
</html>
Your HTML is invalid.
A form can't be a child of a table element, and an input can't be a child of a table row element.
Only table cells can be children of a table row.
Additionally, you can't use “ (LEFT DOUBLE QUOTATION MARK) to delimit attribute values. Only " (QUOTATION MARK) or ' (APOSTROPHE ).
Use a validator.
Aside: Once you solve that problem you will discover that Scripting.FileSystemObject is not made available to web browsers. You can't write to arbitrary files with browser-side JS.
Your doublequotes are wrong.
This is how it is:
<input type=“submit” value=“Submit”>
This is how it needs to be:
<input type="submit" value="Submit">
Because of that doublequotes, type is not recognised and by default input type is text. Thats why you are having that problem.
You had multiple problems.
First the use the correct quotes helps a lot of issues.
Place your submit button in a td element so it won't be placed directly into a row.
You used class as a variable name in your javascript which is not allowed.
function WriteToFile(passForm) {
//No Idea what this is. Wont work in snippet
//set fso = CreateObject("Scripting.FileSystemObject");
//set s = fso.CreateTextFile(“using theseee / this.txt ", True);
//use the correct quotes
var year = document.getElementById('year');
//it's not allowed to use class as a variable
var classEl = document.getElementById('class');
var topic = document.getElementById('topic');
var title = document.getElementById('title');
var question = document.getElementById('question');
var option1 = document.getElementById('answer1');
var option2 = document.getElementById('answer2');
var option3 = document.getElementById('answer3');
//use the correct quotes
console.log("Title: " + title);
console.log("Question: " + question);
console.log("Option1: " + answer1);
console.log("Option2: " + answer2);
console.log("Option3: " + answer3);
console.log("-----------------------------"); s.Close();
}
<html>
<head>
<title>Quiz Form</title>
<link rel=“stylesheet” href=“TRYstyle.css”>
</head>
<body>
<h3>Quiz form</h3>
<table>
<form onSubmit="WriteToFile(this.txt)">
<tr>
<td>Title</td>
<td><input type="text" placeholder="Title" name="title" id="title" maxlength="200"/></td>
</tr>
<tr>
<td>Question</td>
<td><input type="text" placeholder="Question" name="question" id="question" maxlength="200"/></td>
</tr>
<tr>
<td>Answer</td>
<td><input type="text" placeholder="Answer" name="answer1" id="answer1" maxlength="200"/></td>
</tr>
<tr>
<td>Answer</td>
<td><input type="text" placeholder="Answer" name="answer2" id="answer2" maxlength="200"/></td>
</tr>
<tr>
<td>Answer</td>
<td><input type="text" placeholder="Answer" name="answer3" id="answer3" maxlength="200"/></td>
</tr>
<tr>
<td colspan="2">
<input type="submit">
</td>
</tr>
</form>
</table>
</body>
</html>

Javascript to show content if checkbox is checked

In this Fiddle I have made script that should show the form if the checkbox is checked but I can't make it work. It says that the function is unknown variable.
Html
<input type="checkbox" id="_My.notFinal" onclick='toggleCheckbox();'>
<label>
<b>Buying for someone else.</b>
</label>
<span id="LicenseCustomer" style="display:none">/*some form*/</span>
And javascript
function toggleCheckbox() {
var lfckv = document.getElementById("_My.notFinal").checked;
if (lfckv) {
document.getElementById("LicenseCustomer").style.display = "block";
} else {
document.getElementById("LicenseCustomer").style.display = "none";
}
}
https://jsfiddle.net/00gckvxw/1/
Here it is the corrected version https://jsfiddle.net/00gckvxw/24/.
document.getElementById("_My.notFinal").onclick = toggleCheckbox;
It has to do with when the events are attached. check this out: testing a function in jsfiddle.
I also changed the span to div and class attribute to id. I wouldn't recommend using <tr> inside a <div> or <span>, better use id on <tr> directly or use <tbody> if you have multiple lines.
I think you missed out to include the Javascript file in your in html, because it is not able to find the function toggleCheckbox on click of checkbox. Also
Also span element has class = 'LicenseCustomer', change this to id='LicenseCustomer'
try including inline script
<script>
function toggleCheckbox() {
var lfckv = document.getElementById("_My.notFinal").checked;
console.log(lfckv);
if (lfckv) {
document.getElementById("LicenseCustomer").style.display = "block";
} else {
document.getElementById("LicenseCustomer").style.display = "none";
}
}
</script>
<input type="checkbox" id="_My.notFinal" onclick='toggleCheckbox();'>
<label><b>Buying for someone else.</b>
<label>
<span id="LicenseCustomer" style="display:none">
<tr valign=middle>
<td class="bodycopy" align=right width=160><b>License Contact:</b> </td>
<td class="smallcopy" nowrap><input name="_My.LicenseContact" type="text" class="inputBox" size="32" _label="<br>License Contact"></td>
</tr>
<tr valign=middle>
<td class="bodycopy" align=right><b> License E-mail Address:</b> </td>
<td class="smallcopy" nowrap><input name="_My.LicenseEmail" type="text" class="inputBox" size="32" _label="<br> License E-mail Address"></td>
</tr>
<tr valign=middle>
<td class="bodycopy" align=right><b> License Phone:</b> </td>
<td class="smallcopy" nowrap><input name="_My.LicensePhone" type="text" class="inputBox" size="32" _label="<br> License Phone"></td>
</tr>
</span>
corrected version:
http://pastebin.com/RrMD78AG
Few mistakes i want to tell you:-
first you are using class="LicenseCustomer" and you are using document.getElementById selector (it cannot get element with class name).
second you are using onclick="toggleCheckbox();", when you calling function you does not have to use 'semicolon' at the end of a function name (its an incorrect syntax) - onclick="toggleCheckbox()" (no semicolon).
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<input type="checkbox" id="_My.notFinal" class='checkbox'>
<label><b>Buying for someone else.</b>
</label>
<span class="LicenseCustomer" style="display:none">
<tr valign=middle>
<td class="bodycopy" align=right width=160><b>License Contact:</b> </td>
<td class="smallcopy" nowrap><input name="_My.LicenseContact" type="text" class="inputBox" size="32" _label="<br>License Contact"></td>
</tr>
<tr valign=middle>
<td class="bodycopy" align=right><b> License E-mail Address:</b> </td>
<td class="smallcopy" nowrap><input name="_My.LicenseEmail" type="text" class="inputBox" size="32" _label="<br> License E-mail Address"></td>
</tr>
<tr valign=middle>
<td class="bodycopy" align=right><b> License Phone:</b> </td>
<td class="smallcopy" nowrap><input name="_My.LicensePhone" type="text" class="inputBox" size="32" _label="<br> License Phone"></td>
</tr>
</span>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
</body>
</html>
Below is the Javascript
$(document).ready(function()
{
$(".checkbox").change(function() {
if(this.checked)
{
$(".LicenseCustomer").css('display','block');
}
else
{
$(".LicenseCustomer").css('display','none');
}
})
});
Demo : https://jsbin.com/bowicivupa/edit?html,js,console,output
Try to something like this.
function toggleCheckbox(){
var lfckv = document.getElementById('myCheck').checked;
if(lfckv){
document.getElementsByTagName("span")[0].setAttribute("style", "display:none");
} else {
document.getElementsByTagName("span")[0].setAttribute("style", "display:block");
}
}

how to execute java code from a jsp page using a button?

this is my jsp code:
EMAIL.JSP
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Example</title>
</head>
<body>
<form method="post" action="">
<center>
<table border="1" width="30%" cellpadding="3">
<thead>
<tr>
<th colspan="2">Enter the information</th>
</tr>
</thead>
<tbody>
<tr>
<td>To Address</td>
<td><input type="text" name="uname" value="" /></td>
</tr>
<tr>
<td>Subject</td>
<td><input type="text" name="uname" value="" /></td>
</tr>
<tr>
<td>AttachFile</td>
<td<inputtype="text"value=".\ogc\hb1_800.jpg"id=".\ogc\hb1_800.jpg" />
</td>
</tr>
<tr>
<td><input type="reset" value="Clear" /></td>
<td><input type="Submit" value="Submit" /></td>
</tr>
</tbody>
</table>
</center>
</form>
and on clicking the submit button i need to execute the java code:
final.java which is below:-
FINAL.JAVA
package com.grid;
public class final {
public static void main(String[] args) {
String ToAddress = new String[]{"8789951#gmail.com"};
String Subject = "Hi this is test Mail";
String AttachFile = {".\ogc\notepad\styles\thumbs\hb1_800.jpg"};
new Email().sendMail(ToAddress,Subject,AttachFile);
}
}
it calls the email.java
package com.grid;
import java.io.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
public class Email{
private String SMTP_HOST = "smtp.gmail.com";
private String FROM_ADDRESS = "n123f#gmail.com";
private String PASSWORD = *****";
private String FROM_NAME = "Abc";
public boolean sendMail(String ToAddress,String Subject,String AttachFile) {
try {
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST);
props.put("mail.smtp.auth", "true");
props.put("mail.debug.auth", "true");
props.put("mail.smtp.ssl.enable", "true");
Session session = Session.getInstance(props, new SocialAuth());
MimeMessage msg = new MimeMessage(session);
InternetAddress from = new InternetAddress(FROM_ADDRESS, FROM_NAME);
msg.setFrom(from);
InternetAddress[] ToAddress = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++) {
ToAddress = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, ToAddress);
msg.setSubject(Subject);
MimeBodyPart msgBodyPart = new MimeBodyPart();
// Fill the message
msgBodyPart.setText("This is message body");
// Create a multipart message
Multipart multipart = new MimeMultipart();
// Set text message part
multipart.addBodyPart(msgBodyPart);
// Part two is attachment
if (FileName != null && FileName.length > 0)
{
for (String filePath : FileName)
{
MimeBodyPart attachPart = new MimeBodyPart();
try {
attachPart.AttachFile(filePath);
} catch (IOException ex) {
ex.printStackTrace();
}
multipart.addBodyPart(attachPart);
}
}
/*DataSource source = new FileDataSource(filename);
msgBodyPart.setDataHandler(new DataHandler(source));
msgBodyPart.setFileName(filename);
multipart.addBodyPart(msgBodyPart);*/
msg.setContent(multipart);
Transport.send(msg);
return true;
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(MailUtil.class.getName()).log(Level.SEVERE, null, ex);
return false;
} catch (MessagingException ex) {
Logger.getLogger(MailUtil.class.getName()).log(Level.SEVERE, null,ex);
return false;
}
}
class SocialAuth extends Authenticator {
#Override
protected PasswordAuthentication getPasswordAuthentication() {
new PasswordAuthentication(FROM_ADDRESS, PASSWORD);
}
}
}
Now my doubt is how to execute final.java (which is a running code) on clicking the button submit in email.jsp page?
Here is a simple servlet for demonstration:
JSP:
<form method="post" action="/email">
<center>
<table border="1" width="30%" cellpadding="3">
<thead>
<tr>
<th colspan="2">Enter the information</th>
</tr>
</thead>
<tbody>
<tr>
<td>To Address</td>
<td><input type="text" name="to" value="" /></td>
</tr>
<tr>
<td>Subject</td>
<td><input type="text" name="subject" value="" /></td>
</tr>
<tr>
<td>AttachFile</td>
<td> <input type="text" name="file" value=".\ogc\hb1_800.jpg"id=".\ogc\hb1_800.jpg" />
</td>
</tr>
<tr>
<td><input type="reset" value="Clear" /></td>
<td><input type="Submit" value="Submit" /></td>
</tr>
</tbody>
</table>
</center>
</form>
Servlet:
#WebServlet(name="mytest", urlPatterns={"/email"})
public class MailServlet extends javax.servlet.http.HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException {
String to = request.getParameter("to");
String subject = request.getParameter("subject");
String file = request.getParameter("file");
new Email().sendMail(to,subject,file);
response.getWriter().println("Email sent");
}
}

Jsfiddle code not working in localhost wamp

i have implemented validation for fundtransfer in jsfiddle.
it works fine in jsfiddle but not working in localhost.
i am using wamp.
here is my jsfiddle link - http://jsfiddle.net/BzdfN/31/
but when i am implementing this in localhost.its not working.
my html code is
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="validate.js"></script>
<title> Infy Bank Fund Transfer Entry Page </title>
</head>
<body>
<table class="layout" border="0" width="90%" align="center">
<form name="addcust" method ="POST" action ="http://localhost:8080/myapp/jsp/AddCustomerJSP.jsp">
<td colspan="2">
<table border="0" width="70%" align="center">
<tr>
<td align="center" colspan="2">
<div class="heading2">Infy Bank</div>
</td>
</tr>
<tr>
<td align="center" colspan="2"><p class="heading3">Fund transfer</p></td>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
<td>Payers account no<span class="mandatory">*</span></td>
<td><input type="text" name="text10" id="text10" size="25" />
<div width="100%" id="equal"></div>
</td>
</tr>
<!--<tr>
<td>Payees account no<span class="mandatory">*</span></td>
<td>
<input type="text" name="name" value=2008 maxlength="25">
</td>
</tr>
<tr>
<td>Amount<span class="mandatory">*</span></td><td><input type="text" Value=500 name="state" maxlength="25"></td>
</tr>
<tr>
<td>Description<span class="mandatory">*</span></td><td><input type="text" name="pin" value=self maxlength="6"></td>
</tr>
<tr>
<td><span class="mandatory">*mandatory field</span></td>
<td><input type="submit" name="AccSubmit" value="Submit" onClick="return validatebal();">
<input type="reset" name="res" value="Reset"></td>
</tr>-->
</form>
</table>
<p align="right">Home</p>
</body>
</html>
and my validate.js is
$("#text10").keyup(function(){
$("#text10").blur();
$("#text10").focus();
});
$("#text10").change(function(){
var name = $('#text10').val();
var numbers = /^[0-9]+$/;
var specialChars = "<>#!#$%^&*()_+[]{}?:;|'\"\\,./~`-=";
if (name == "" || name == " " )
{
$("#equal").show();
$("#equal a").html("please enter account number");
}
else if(name.match(numbers))
{
$("#equal").hide();
$("#equal a").html("correct account number"); // alert('All Boxes have elements.');
}
else if(name.match(specialChars))
{
$("#equal").show();
$("#equal a").html("correct account number"); // alert('All Boxes have elements.');
}
else
{
$("#equal").show();
$("#equal a").html("please check your account number correctly");
}
});
So guys can you what i am doing wrong.
please help
start your jQuery with:
$( document ).ready(function() {
.../ and end with:
});
maybe this will solve your problem
In jsfFiddle your code is executed on the onload event.
But with including validate.js in the head the content of the script is execute right at the place where you placed <script src="validate.js"></script>. So your jQuery selectors don't find any elements, because they are not in the DOM at the time the script is executed.
You have different possibilities.
Wrap the content of your validate.js into jQuery(function() { /*your code of validate.js **/ })
Another possibility is to place <script src="validate.js"></script> at the end of your document instead placing it in the head.
You can use delegated events like $(document).on("keyup","#text10", function() { /* .... */ }); that way it does not matter if #text10 is in the DOM at this time.
wrap your validate.js code in jQuery ready function as follows should solve the issue:
$(document).ready(function() {
// validate.js code
});

Categories

Resources