Trigger an enter key against the text field [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm very new to Jquery And I'm trying to stimulate the enter key on a text field. But its not working.
I have an textfield with id deviceSearchByName. I have some text typed in deviceSearchByName and when I press enter search results will be displayed. I'm trying this code from safari console:
var e = jQuery.Event("keydown");
e.which = 13; // Enter
$("#deviceSearchByName").trigger(e)
Its not triggering the enter key event.
Edit:
var e = jQuery.Event("keyup");
e.which = 8; // Enter
$("#deviceSearchByName").trigger(e)
JSFiddle link. In my webpage when I press enter manually (after typing the search keyword) I get the search results. But when I trigger using JS. I dont see any event happened against that textbox and no results are been displayed.
Where I'm making the mistake?

You can see here (http://api.jquery.com/trigger/) that trigger can have two arguments. One for the event and one for extra parameters.
So you need to do :
var e = jQuery.Event("keydown");
e.which = 13; // Enter
$("#deviceSearchByName").trigger('keydown', e);

Related

unable to deal with empty field in my code [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Here I need to provide officename to find the address ,but one challenge which I am facing that if user does not type anything and hit search button then I want to acknowledge them to fill the req input.
I have implemented one function also that will get invocked when someone hits the search button.But I am unable to proceed for further execution.
You can do it something like this:
var searchText = document.getElementById('<ID_OF_INPUT_FIELD>').value;
if(!searchText) {
alert('Please enter something');
}
<input id =“officeInput” name=“officeiupit” size=“35”>
Point to critical input fields and save in global variables:
oOf=document.getElementById(‘officeInput’);
When a search button has been clicked, make a copy of the textbook content inside your function which you've made:
var sInputText=oOf.value;
In this case inside your function just put
if(!sInputText)
alert(“You must enter an input.“);

Capture updated text from h tag after change in input field [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am new to Javascript.So please excuse me if I am asking anything silly. I have a sample Shiny application Statistics Dashboard which can be used to find some basic statistical measures such as Mean, Median etc. for any metric. Users have to upload a csv file based on which the dashboard selects all the numeric variables within the file and provides an option to select any numeric variable to analyze as a dropdown. I want to add a javascript code in the application which will capture the updated measures (e.g. mean) after a user has selected a particular dimension from the dropdown. For example, suppose the default selected dimension in the dropdown window is "sales" and the corresponding mean is 325. If I select another dimension (suppose) "profit" then the mean changes to 37. Now I want to add a javascript/jquery code which will capture the mean value of 37 when I select "profit" (from "sales") from the dropdown. I have tried the .change event to check for the change in the dropdown selection and when there is a change, capture the mean value inside the h3 tag. However, I am getting the previous mean value instead of the updated one i.e. I am getting 325 instead of 37 when I select "profit" (from "sales"). Hope I am clear on this.
Am I using the wrong event? How can I capture anything after a certain action occurs and the values are updated?
Feel free to let me know if you need any more details on my query. Looking forward to the help from the community.
I think this is Exactly what you are looking for
Here is a code which will detect any changes in a certain element.
HTML:
<input type="text" id="Profit"></input>
<h3 id="MeanLabel">100</h3>
Javascript/Jquery:
$(document).ready(function() {
$("#Profit").on("change", function()
{
$("#MeanLabel").text(this.value);
});
initialValue = $("#MeanLabel").text();
CheckChanges();
})
function CheckChanges()
{
if($("#MeanLabel").text() != initialValue)
{
//The Label Changes!
initialValue = $("#MeanLabel").text();
alert("New Label is: " + initialValue)
}
setTimeout(CheckChanges, 200)
}
This is the working sample.
https://jsfiddle.net/h68nxu4h/

When a button is clicked, a prompt comes up and ask user for input, input (email) gets appended to the end of a predefined link. How to? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Apologies for a long title, I'm a beginner but what I want to achieve should be pretty simple to do, I think :)
I have a button on my website that points to a link, let's say mysite.com/abc=$userid
Once the button is clicked the prompt should open up and ask the user for their email address. After they input and press ok/submit I'd like to take their input and replace $userid with it e.g. mysite.com/abc=john#mail.com and open this link in a new tab.
Hope the question makes sense and I'd be eternally grateful for any tips on how to achieve this. Please help.
Kind regards,
Jack Dunn
Quick jquery solution as this answer is marked with jQuery tag :
$('#myButton').click(function() {
var email = prompt('Please enter your email');
if (email != null) {
location.href = location.href + "?abc=" + email
}
});

(Preferably jQuery) Rich Textbox without any toolbar and just bullets on by Default [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
Hello All and Thanks in Advance
Special Note:
There is no question of why or why not something else. It has to be like this.
I have a problem where I want to let a user input data in a textfield. However the data must be in bulleted format. So as soon as the user presses 'Enter' another bullet starts to enter another row of data.
This data needs to be saved in a database and displayed as well during edit scenario.
Is it possible to use a jQuery plugin. Hide/Remove toolbar. Enable bullets by default so when the control is accessed a bullet appears straight away where user can enter a sentence. Press enter which starts another bullet to enter data and vice versa.
Regards!!!
This post doesn't have a specific question it seems so I'll tackle the front end aspect of putting borderless textboxes with bullets on the side as well as inserting new ones when pressing enter.
You will have to capture the enter key event when they are focused on the textbox. In order to do this you will need to use code similar to this:
$('input[type=text]').bind("enterKey",function(e){
var input = addInput("");
$(input).focus();
});
$('input[type=text]').keyup(function(e){
if(e.keyCode == 13)
{
$(this).trigger("enterKey");
}
});
For the border-less inputs that will just be CSS to remove the border such as this:
.noBorder {
border: 0px none;
}
Just apply that class to your inputs.
Lastly for the bullets you will just need to have a <ul> tag and add <li> items with the inputs inside.
Here is a working example and I have even wrapped events around textbox changes so you can save to the database: http://jsfiddle.net/cv7L11sn/

Specific Keymapping JS [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm not super familiar with DOM events and such. Currently, what I'd like to do is click on the first object, which is a HTML link with the class name "test", when the user presses 1 on the keyboard and or keypad as well. I'd be using the keydown event since it seems more supported then keypress. How would I go as to doing this?
Using jquery for example:
$(document).on('keydown', function(event) {
if(event.keyCode == 49 // press key 1 on keyboard
|| event.keyCode == 97) // press key 1 on keypad
location.href = $('a.test').attr('href');
});
jsFiddle

Categories