getting dropdown selected value using DOJO - javascript

I need to get a selected value using dojo, from the dropdown without redirecting to another page.
I have tried something like this:
dojo.addOnLoad( function() {
dojo.connect(dojo.byId('#inquiry_type'), "onchange", function(evt) {
alert("changed!");
console.log("option Changed to: "+evt.target.value);
dojo.stopEvent(evt);
});
});
Above code gave me undefined in console. Can anyone help me with dojo code?

Omit the # in your call to dojo.byId. It just needs the name. Using the # syntax is what you would do with dojo/query.

Related

I got a TypeError after i tried to implement "Edit" and "Delete" in a JavaScript form

I need to make a JavaScript form that allows you to edit or delete stuff that you submitted.
I used this tutorial (https://www.youtube.com/watch?v=-rNQeJi3Wp4), but when I tried to implement the edit function, it doesn't create the hyperlink, and when I click on it, it says
script.js:14 Uncaught TypeError: Cannot read property '0' of undefined.
at editRow (script.js:14)
at HTMLAnchorElement.onclick (index.html:1)"
Also I found out that the "selectedRow.cells" returns "undefined".
here is the code:
https://pastebin.com/pZVQ91D0
here is the function:
function editRow(td) {
//document.getElementById("AS").deleteRow(td);
selectedRow = td.parentElement.parentElement;
console.log(selectedRow.cells);
input.value = selectedRow.cells[0].innerHTML;
}
(The guy in the video solved the whole thing differently. I just tried to implement SOME of his code into my approach.)
Can you help me?
The value of selectedRow.cells is undefined so you are getting that error. The cells should have an some value. If you can add more code it will be helpful.

Unable to read 'checked' property in Qunit test case

I have below mentioned code in my JS file.
initialize: function () {
if (!$("#Res").is(':checked'))
{
$("#Res").attr('checked', true);
}
}
When I tried to run test case using Qunit.js and blanekt.js. It shows me error that "Cannot read property 'checked' of null"
Can please anyone assist me to fix this issue or re-write test case. I am using Jquery 1.4.1.js version. Is issue related to version of Jquery?
test("initialize test", 1, function () {
$('<input>').appendTo("body");
$('<select>').appendTo("body");
$('<input>', { type: "checkbox", checked: true, id: "Res"}).appendTo("body");
var result = mydomain.initialize();
equal(undefined, result, "passed");
$('input, select').trigger("blur");
ok(true, "blur event called");
$('input, select').trigger("change");
ok(true, "change event called");
$("input").remove();
$("select").remove();
});
Option 1.
Using your browser's dev tools, execute the following command:
$("#Res")
If you come up with null it means that your control isn't being created as you were expected.
Option 2.
If Option 1 is fine then you might be calling the initialize function before the input is created.
In any case it is difficult to help you because you haven't posted the resulting HTML by viewing the source of the page once it loads.
Option 3.
Checkbox libraries commonly use css and hide the actual checkbox input after they've initialised. You should check for available events or properties to check their state.

Is it possible to instantiate all datetimepicker's with one javascript call?

I have PHP generating a random amount of bootstrap-datetimepicker widgets, and I'm trying to instantiate them with one jQuery function, rather than one for each.
They all have the class .datepicker, but
$(function () {
$('.datepicker').datetimepicker();
});
does not work.
Any ideas?
EDIT:
I just tried
$(function () {
$('.datepicker').each(function(){
$(this).datetimepicker();
});
});
however, I still get the error Uncaught TypeError: Cannot read property 'dateOptions' of null.
EDIT: Fixed.
Hi,
I am working on a legacy codebase, and was using the wrong jQuery to instantiate. Everything works with the latest jQuery.

Undefined variable error that shouldn't be a variable

I've made a piece of code in jquery that assigns a href attribute to a variable. Here's that code:
$('#reactions' + i).attr('href', 'javascript:comments ('+entry.url+','+i+');');
This should assign a call to the javascript function comments. Now I want to use that call on a jquery mobile button, like this:
document.write('Reactions');
But doing this gives me a in FF and Chrome. This is the error from FF±
Uncaught exception: ReferenceError: Undefined variable: i_heart_chaos_ihc_after_dark_independence_day_through_a_bullhornthis_is_what
Error thrown at line 1, column 0 in javascript:comments (i_heart_chaos_ihc_after_dark_independence_day_through_a_bullhornthis_is_what,1);:
comments (i_heart_chaos_ihc_after_dark_independence_day_through_a_bullhornthis_is_what,1);
In this, i_heart_chaos_ihc_after_dark_independence_day_through_a_bullhornthis_is_what is the value of entry.url.
I'm just not getting why this error appears, as far as I know, everything should work.
I know that there are questions looking similar to mine, but I couldn't figure out the answer. If you want to see the whole source, it's here.
Surround entry.url with quotes:
$('#reactions' + i).attr('href', 'javascript:comments ("'+entry.url+'",'+i+');');
The best way to fix the issue is to do it the "jQuery way". Instead of adding a href attribute that executes JavaScript, add a click event:
$('#reactions' + i).click( function() {
comments( entry.url, i );
});
Similarly don't use document.write() but add elements to the document using jQuery functions.

Simple jQuery code contains a syntax error that I can't find

I've got this (remarkably) simple JavaScript function that is called when a user clicks a "Cancel" link:
function hideNewUserPanel(){
$('#create_user_panel').slideUp('slow');
$('.right_interior_panel').slideDown('slow');
}
And the code to add the handler:
$(function(){
$('#cancel_create_user_btn').live('click',
function(){ hideNewUserPanel(); }
)
});
Functionally, everything works as expected. Trouble is, when I click the "Cancel" link, Firebug shows an error in the console:
uncaught exception: Syntax error, unrecognized expression: #
I've stepped through the code several times and the error appears at some point before the call to hideNewUserPanel(). At the risk of sounding like one of "those programmers" (the kind that claim to have found a bug in GCC and assume their own code is perfect), the exception is being thrown from somewhere within jQuery proper, so I assume the issue is in there. I'm using jQuery 1.3.2 (this is a legacy project using many jQuery plugins that will break if we update to 1.4.x).
Is there anything obviously wrong with my code that I'm simply not seeing? This code is, frankly, very simple and I don't really see what the issue could be.
Thanks!
This:
$(function(){
$('#cancel_create_user_btn').live('click',
function(){ hideNewUserPanel(); }
});
Needs a closing paren after the function, like this:
$(function(){
$('#cancel_create_user_btn').live('click',
function(){ hideNewUserPanel(); });
});
Also, you can write that a bit simpler :), try this:
$(function(){
$('#cancel_create_user_btn').live('click', hideNewUserPanel);
});
You seem to be msising the end of the live call:
$(function(){
$('#cancel_create_user_btn').live('click',
function(){ hideNewUserPanel(); }
); // <===
});
$(function() {
function hideNewUserPanel() {
$('#create_user_panel').slideUp('slow');
$('.right_interior_panel').slideDown('slow');
}
$('#cancel_create_user_btn').live('click', function() { hideNewUserPanel(); });
});

Categories

Resources