jQuery event triggered by space - javascript

I'm trying to have a next button disabled untill 30 seconds after the space bar has been pressed using jQuery in qualtrics. I've tried a lot of suggestions that have already been made, but nothing seems to work. If anyone could help me out here I'd be super grateful, I'm at a real dead end.
Thanks in advance
Qualtrics.SurveyEngine.addOnload(function() {
/*Place Your Javascript Below This Line*/
var InputId = $("QR~" + this.questionId);
InputId.style.display = "none";
this.disableNextButton();
if (e.keyCode === 0 || e.keyCode === 32) {
this.enableNextButton.delay(30);
}
})

$ in Qualtrics is referring to prototypejs.
You would need to run jquery noconflict to be using jquery, and using the correct identifier to match.
Additionally, you have no event handler to capture your keypress.

Related

Press a tab key through Javascript for selenium

I require to test a functionality of an input form, where i have to validate that pressing tab key works through right input fields. I used selenium's action as well as Keys.tab
Actions new tab = new Actions(driver);
newtab.SendKeys(Keys.Tab).Build().Perform();
but due to google chrome version 53.0.2785.116 , its not supporting tab key press and so i want to simulate tab key press through javascript. All the answers only follow to "what to do after" the event is called.
Could anyone give me any insight in this?
EDIT: please note that i need to run this scripts in selenium web driver test. So answers relevant to same would be very helpful.
I did find questions and few confusing answers like
Question A
Question B
I also tried the following solutionLink here but its not working. Does "keyboardEvent" not work anymore? could some one give me a workaround?
Using Jquery you can try:
$("#1234").trigger({type: 'keypress', which: 9, keyCode: 9});
Using JS:
var pressTabKey = new Event('keydown');
document.getElementById('1234').addEventListener('keydown', function() { alert("hi!"); });
document.getElementById('1234').dispatchEvent(pressTabKey);
where 1234 is id of textbox.
In jQuery we use just like follows :
Suppose you have TextBox with Id txtName
$("[id*=txtName]").on('keydown', function(e) {
var keyCode = e.keyCode || e.which;
if (keyCode == 9) {
e.preventDefault();
alert('Tab Pressed');
}
});

Qualtrics: Pressing enter key to emulate continue button

I'm very new to JavaScript, and I'm currently trying to add a custom code to my Qualtrics survey that makes it so pressing the enter key continues the survey. I have a code that should be working; however, I'm getting an "Unexpected token )" error.
Here is the code:
Qualtrics.SurveyEngine.addOnload(function()
{
document.addEventListener("keydown", function(e) {
if (e.keyCode === 13) {
function(){
that.clickNextButton();
}
}
}
});
the "clickNextButton" function was found in the Qualtrics API document and is supposed to emulate the next button click. The function is clickNextButton(), but the example provided has the code as that.clickNextButton().
The example they use is below:
//Hides the next button and displays the question
//for 5 seconds before moving to the next page
this.hideNextButton();
var that = this;
(function(){that.clickNextButton();}).delay(5);
I don't need the hiding button function or the delay, but just wanted to include an example of how it is used.
Any help is much appreciated, thanks in advance!
Here is a simplified version that works (updated to hide NextButton):
Qualtrics.SurveyEngine.addOnload(function() {
$('NextButton').hide();
document.on("keydown", function(e) {
if (e.keyCode === 13) $('NextButton').click();
});
});
It depends on the scope, or specifically where the function clickNextButton resides.
If you don't bother with the timeout you should be able to just remove the word 'that' from your Qualtrics.SurveyEngine function and it should work fine.
It's possible the function is not available in your current scope. So if removing 'that' doesn't work. Put it back in and put var that = this; in the line before your function call. It's far from a tidy way to do things at all but it may fix things for you.
Worth reading this.
http://www.w3schools.com/js/js_scope.asp
Didn't Meatloaf say something like... I'd do anything for scope.... but I don't do THAT?
As said in my comment...See if it solves your error
Qualtrics.SurveyEngine.addOnload(function()
{
document.addEventListener("keydown", function(e) {
if (e.keyCode === 13) {
function(){
that.clickNextButton();
}
}
} ); // here was a missing bracket here
});
So I have a video embedded in a question and I needed to disable to Next button for 15 seconds in that way I would know that autoplay video was watched.
And this worked for me so well:
Qualtrics.SurveyEngine.addOnload(function()
{
//Hides the next button and displays the question
//for 15 seconds before moving to the next page
this.disableNextButton();
var that = this;
(function(){that.enableNextButton();}).delay(15);
});
You can change the (15) seconds to any number, the Next Button will be activated and ready to be clicked next, but not automatically send you to next page.

How to disable 'save image as' option on right click? [duplicate]

This question already has answers here:
How do I disable right click on my web page?
(30 answers)
Closed 8 years ago.
I want to prevent users from right-clicking on image on my site and saving them.
I know there are many work-around for this, but I still need to do it.
Any help?
Also, this site has this feature - http://finsix.com/dart/#section-colors
It can be html, javascript, jquery. Any solution will do.
$("body").on("contextmenu", "img", function(e) {
return false;
});
This is the "new" way in jQuery. Bear in mind anyone with technical knowledge would be able to get around this.
Use the image as a background-image of a div element, This will keep the easy minded people away from saving it ;)
<script type="text/javascript">
function click (e) {
if (!e)
e = window.event;
if ((e.type && e.type == "contextmenu") || (e.button && e.button == 2) || (e.which && e.which == 3)) {
if (window.opera)
window.alert("");
return false;
}
}
if (document.layers)
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown = click;
document.oncontextmenu = click;
</script>
I have found this script on selfhtml.org.
This function is originally designed to disable the client side context menu and to insert your own context menu. But it can be used for this too.
But keep in mind: By using browser addons like NoScript or opening the image url user could get around this.

JQuery UI Dialog: Password inputs causing freezing

This is a odd behavior that seems to only happen in Chrome and with JQuery UI. When entering characters into a password field at first everything functions correctly. However, if you attempt to backspace to the last letter in the input, the browser locks up all client side operations. Also, if you try and highlight the characters entered and backspace the client side operations freeze.
Just reaching out to see if anyone has encountered this same issue, and how they resolved it.
In order to experience the issue, we have the dialog auto opening on 2+ unique page home views. Here is a listings page so it can be triggered, I apologize for the inconvenience but I can't remove the counter.
Page: http://www.christineleeteam.com/area/eagleharbor
I had the same problem but cache clearing didn't help. I'm sure it isn't a jquery ui bug.
Here is my solution:
$('input[type="password"]').on('keydown', function(event){
if (event.which == 8) { //backspace event
event.preventDefault();
$(this).val('');
}
});
This code is clearing the whole password field on one backspace event.
We encountered the same issue, and used Benkod's solution.
We improved it a little to also handle cases where the password text is deleted with the delete key (and not backspace).
Another case is when all the text in the control is selected and new text is typed to replace it.
Here is the script we used:
Sys.Application.add_load(function() {
$('input[type=password]').keydown(function(event) {
var isAllTextSelected = this.value.slice(this.selectionStart, this.selectionEnd) == this.value;
var isLastChar = $(this).val().length == 1;
if (isAllTextSelected && $(this).val().length > 0) {
$(this).val('');
}
if ((event.which == 8 || event.which == 46) && (isLastChar || isAllTextSelected)) { //backspace event
event.preventDefault();
$(this).val('');
}
});
});
Same problem here (FWIW, I'm using Twitter Bootstrap, but the issue was the same). It looks like it's caused by having a lot of content preceding the input. Placing the input higher--above the bulk of other content--did the trick for me. A work around, but better than nothing.

capture right click through Javascript, withouth wmode

Flash player has a bug in using anything other than wmode="window" in Firefox/Chrome when using any other language than English. This bug is reported and not fixed yet
http://bugs.adobe.com/jira/browse/FP-501
The issue can be seen better here -
http://www.5etdemi.com/blog/archives/2005/06/firefox-wmodetransparent-is-completely-screwy-and-breaks-textfields/
Now to my problem - im trying to use Uza's right click solution ( http://www.uza.lt/blog/2007/08/solved-right-click-in-as3 ) in my application, but am stuck with problem of wmode. The event capturing doesnt seem to work with wmode="window" and i need multiple languages to work on my app as well.
Is there any solution to this that anyone has identified? Or is there any way that the right click can be captured without setting wmode.
Any help will be greatly appreciated. Thanks!!
Fortunately you most often want to know if the right button has been clicked. Since W3C and Microsoft happen to agree on this one and give button a value of 2, you can still detect a right click.
function doSomething(e) {
var rightclick;
if (!e) var e = window.event;
if (e.which) rightclick = (e.which == 3);
else if (e.button) rightclick = (e.button == 2);
alert('Rightclick: ' + rightclick); // true or false
}
http://www.rgagnon.com/jsdetails/js-0061.html
http://www.quirksmode.org/js/events_properties.html
http://unixpapa.com/js/mouse.html
http://www.javascripter.net/faq/leftvsri.htm

Categories