I want to know how to catch 'Go' pressed event using PhoneGap.
I have a form with 2 input fields. How do I catch when user has pressed "Go" in keyboard. I tried butting the input fields in a Form and added a onSubmit method. And in my Js I have the method.
function onLoginSubmit(e){
console.log('submit pressed');
e.preventDefault();
}
But looks like the method is never called. What is the best way of doing it?
An example would be great.
try following code:
<head>
<script language="javascript">
function show()
{
if(window.event.keyCode == 13)
{
alert(window.event.keyCode);
}
}
</script></head>
<body>
<input type="text" name="textfields" onKeyPress="show();">
</body>
Related
i have a button that i use to delete records
every time bootbox shows the confirm its closes automatically
here in the example the "cancel" button does not word
where is the mistake?
function ConfermaCancella()
{
// e.preventDefault();
bootbox.confirm("Sure to delete?", function (result) {
if (result) {
return true;
} else {
return false;
}
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="http://bootboxjs.com/bootbox.js"></script>
<input type="button" onclick = "return ConfermaCancella();" ID="ImageButton3" value="Delete" />
As noted in the documentation:
All Bootstrap modals, unlike native alerts, confirms, or prompts,
generate non-blocking events. Because of this limitation, code that
should not be evaluated until a user has dismissed your dialog should
be placed (or called) within the callback function of the dialog.
So, if you want something to happen only if the user confirms the action, you need to move your code into a callback, like so:
function ConfermaCancella(){
bootbox.confirm('Confirm delete?', function(result){
/* 'result' is a truthy value */
if(result){
/* Do your delete action, probably using AJAX actions */
}
});
return false;
}
I need to create a timer for my website. I am setting up a form with multiple choice questions. i want users to submit the form/ answers at a specified time say 30 minutes,.. if the time elapses the submit button get disabled and alert message; time is up, Test failed.
Help with entire code; Jquery, and PHP Pease;
For this you can use the setTimeOut() javascript function.
The following line for example shows an alert box with the text Hello, after 3 seconds.
setTimeout(function(){ alert("Hello"); }, 3000);
In your case you want to disable a submit button and show an alert after 30 minutes, 30 minutes = 30*60 = 1800 seconds, equals 1800000 miliseconds.
So the code becomes like this:
setTimeout(function(){
//disable the button with id="submitbutton"
document.getElementById('submitbutton').disabled = true;
alert("Time out!");
}, 1800000);
To make this work once the page is loaded you need to place it in a javascript file or <script></script> tags and wrap it in the on document ready event. The complete code is then:
<html>
<head>
</head>
<body>
Your HTML here with the <input type="submit" id="submitbutton">
<script>
// self executing function
(function() {
setTimeout(function(){
//disable the button with id="submitbutton"
document.getElementById('submitbutton').disabled = true;
alert("Time out!");
}, 1800000);
})();
</script>
</body>
</html>
I have the following function:
<script>
function assign()
{
String val="";
String val = document.form1.text1.value;
System.out.println(val);
}
</script>
i am trying to call the function in the button click as shown below:
<button type="button" onclick="assign()">Display</button>
When i click on the button nothing happens. I want the string value in the text box to be printed on the console.Please help
First of all, if you are trying to call JavaScript on button click, then your syntax is wrong. See, you are mixing Java with JavaScript (code) in script tag, that is invalid.
Use like this:
<script>
function assign() {
var val = "";
val = document.form1.text1.value;
alert(val); or console.log(val);
}
</script>
and
<button type="button" onclick="javascript:assign();">Display</button>
I'm trying to call a function after any form with the class shown below is submitted. However, this doesn't seem to be working for me (the form submits, but the submit button remains active and the loading image is not shown).
$(document).ready(function() {
$('.uniForm').submit(function() {
$('#loadingImage').show();
$(':submit',this).attr('disabled','disabled');
return true;
});
});
Here's some HTML:
<form class="uniForm" id="formABC">
//...form.... here
</form>
<img src="loadimage.gif" style="display: none;" id="loadingImage">
does anyone see anything inherently wrong with this that would be preventing things from working correctly?
I have a feeling it's just not being called correctly. Can I call it myself via some HTML like this?
<button type="button" class="primaryAction" alt="Submit Form" onclick="$('#formABC').submit();">Submit Form</button>
Following your comment, it seems the binding of the handler function to the submit event might be taking place before the form element has been loaded into the DOM.
Ideally, you should bind event handlers only after the DOM has finished loading.
For example:
$(document).ready(function() {
$('.uniForm').submit(function() {
...
});
});
Put an id on the submit input/button and try this:
$('#mySubmitButton').click(function(e) {
e.preventDefault();
e.stopPropagation();
$(this).attr('disabled','disabled');
$('#loadingImage').show(function() {
$(this.form).submit();
});
});
There is a jQuery plugin named jQuery Form Plugin which helps to submit your form from ajax without refresh and then you can do the rest of actions on its success (which occurs exactly after successful form submission):
jQuery(document).ready(function () {
jQuery('#my_submit_button').click(function (e) {
jQuery(this.form).ajaxSubmit({
target: false,
success: function ()
{
your_other_stuff();
},
});
});
});
function your_other_stuff(){
// rest of things
}
Try something else:
$('.uniForm input[type=submit]').click(function(){
$('.uniForm').submit();
//doStuffafterSubmit
});
I am building a small landing page with a simple demo e-mail signup form. I want to have the form field open up when focused, and then shrink back down on blur.
However the problem I'm facing is when you click the submit button this instigates the blur function, hiding the button and shrinking the form. I need to find a way to stop the .blur() method only when the user is clicking to focus on the submit button. Is there any good workaround for this?
Would appreciate any help I can get!
I know this question is old but the simplest way to do it would be to check event.relatedTarget. The first part of the if statement is to prevent throwing an error if relatedTarget is null (the IF will short circuit because null is equivalent to false and the browser knows that it doesn't have to check the second condition if the first condition is false in an && statement).
So:
if(event.relatedTarget && event.relatedTarget.type!="submit"){
//do your animation
}
It isn't the prettiest solution, but it does work. Try this:
$("#submitbtn").mousedown(function() {
mousedownHappened = true;
});
$("#email").blur(function() {
if (mousedownHappened) // cancel the blur event
{
mousedownHappened = false;
}
else // blur event is okay
{
$("#email").animate({
opacity: 0.75,
width: '-=240px'
}, 500, function() {
});
// hide submit button
$("#submitbtn").fadeOut(400);
}
});
DEMO HERE
Try this inside .blur handler:
if ($(':focus').is('#submitbtn')) { return false; }
why not rely on submit event instead of click? http://jsbin.com/ehujup/5/edit
just couple changes into the html and js
wrap inputs into the form and add required for email as it obviously suppose to be
<form id="form">
<div id="signup">
<input type="email" name="email" id="email" placeholder="me#email.com" tabindex="1" required="required">
<input type="submit" name="submit" id="submitbtn" value="Signup" class="submit-btn" tabindex="2">
</div>
</form>
in js, remove handler which listen #submitbtn
$("#submitbtn").on("click", function(e){
e.stopImmediatePropagation();
$("#signup").fadeOut(220);
});
and use instead submit form listerer
$("#form").on("submit", function(e){
$("#signup").fadeOut(220);
return false;
});
you may use $.ajax() to make it even better.
Doing this you gain point in terms of validation and the native browser's HTML5 validator will make check email format where it is supported.