|
If that is your actual code and not just a copy/paste error, your if statement is not testing the _confirm variable (but I would expect that to be true all the time because confirm is a function).
|
|
|
|
|
 It's not the actual code, just an example. I did some searching before my post and tested some other thoughts. Some thoughts talked about it being an async function and the code just ran through.
The code is pretty large in size, but I will post it. It's all on one page or external script file.
I did test it compressed and uncompressed thinking that my gulp script that compresses the script for production use was making an error of some sort.
The only thing that I can think of is a bug in Firefox, but I doubt that!
$(document).ready(function () {
$("#sectionDelete").click(function () {
$("#sectionForm").validate({
ignore: "",
errorClass: 'input-validation-error',
rules: {
Section_DeptID: {
required: true,
minLength: 1
},
Section_SectiontID: {
required: true,
minLength: 1
},
Section_Name: {
required: true,
minLength: 2
},
Section_Desc: {
required: true,
minLength: 2
}
},
messages: {
Section_Name: 'Section requires a name',
Section_Desc: 'Section requires a description'
},
highlight: function (element, errorClass) {
$(element).addClass(errorClass);
},
unhighlight: function (element, errorClass) {
$(element).removeClass(errorClass);
},
success: function (result) {
if (result === "1") {
return true;
}
else {
return false;
}
}
});
if ($("#sectionForm").valid()) {
var deptID = parseInt($("#Section_DeptID").val()),
sectionID = parseInt($("#Section_SectionID").val());
if ((isNaN(deptID) || deptID === -1) && (isNaN(_sectionID) || sectionID === -1)) {
$("#selectSection").text('You must select a section first!').addClass('text-danger');
}
else {
sectionDelete();
}
}<br />
});
});
This is the function that is called from above.
function sectionDelete() {
var $e_Section_DeptID = $("#Section_DeptID"),
$e_Section_SectionID = $("#Section_SectionID"),
$e_Section_Name = $("#Section_Name"),
$e_sContainer = $("#Section_Container"),
_deptID = parseInt($e_Section_DeptID.val()),
_sectionID = parseInt($e_Section_SectionID.val()),
_name = $e_Section_Name.val(),
_confirm = confirm('Are you sure you want to delete the section ' + _name);
if (_confirm === true) {
$e_sContainer.empty().append(pWait);
$.ajax({
type: "POST",
cache: true,
dataType: "json",
url: '/Ajax/json_section_delete',
data: { DeptID: _deptID, SectionID: _sectionID },
error: function (response) {
debugger;
thisObj.toggleClass('active');
alert("http code: " + response.status + " Error: json_sections_load - data: " + response);
},
success: function (data) {
if (data.length === 0) {
$e_sContainer.empty().append(pNull);
}
else {
var sections = '<ul class="nav nav-pills nav-justified">';
for (var x = 0; x < data.length; x++) {
if (data[x].Enabled === true) {
sections += '<li class="col-xs-3" style="width: 33%; float: left; margin: 1% 0;"><button class="section btn btn-success btn-sm" title="' + data[x].Description + '" data-val="1" onclick="sectionRecordLoad(this, ' + data[x].SectionID + '); return false;" type="button">' + data[x].Name + '</button></li>';
}
else {
sections += '<li class="col-xs-3" style="width: 33%; float: left; margin: 1% 0;"><button class="section btn btn-warning btn-sm" title="' + data[x].Description + '" data-val="0" onclick="sectionRecordLoad(this, ' + data[x].SectionID + '); return false;" type="button">' + data[x].Name + '</button></li>';
}
}
sections += '</ul>';
$e_sContainer.empty().append(sections);
}
}
});
}
}
|
|
|
|
|
|
I was using another web app I wrote and went to delete a record, and the same thing happened. Thanks for double checking that, wasted a couple of hours on it.
Thanks!
|
|
|
|
|
I wrote this manual validator for a SPA form.
It's works, just cosmetically wrong.
So the validator creates a label element under the textbox, and assigns the textbox class to the label instead of the class for the label.
I tried removing the class and adding the correct one, but I just can't seem to hookup the element.
$(element.form).find("label[for=" + element.id + "]")
Dynamic Label created by JQuery.Validate, it should be field-validation-error so that its red text on on the inherited background color white. But currently it's a red background and border with black text.
<label for="Section_Desc" class="input-validation-error" id="Section_Desc-error">Section requires a description</label>
This is my validation rule that I wrote.
var validator = $("#sectionForm").validate({
errorClass: 'input-validation-error',
rules: {
Section_Name: {
required: true,
minLength: 2
},
Section_Desc: {
required: true,
minLength: 2
}
},
messages: {
Section_Name: 'Section requires a name',
Section_Desc: 'Section requires a description'
},
highlight: function (element, errorClass) {
$(element).addClass(errorClass);
$(element.form).find("label[for=" + element.id + "]")
.removeClass(errorClass)
.addClass('field-validation-error');
},
unhighlight: function (element, errorClass) {
$(element).removeClass(errorClass);
$(element.form).find("label[for=" + element.id + "]")
.addClass('field-validation-valid')
.removeClass('field-validation-error');
}
});
|
|
|
|
|
I had to add the microsoft unobtrusive validator
|
|
|
|
|
Several times, I have had to implement multidimensional array constructs using JavaScript but encountered difficulties. Since then, I'd been using other languages to
achieve this purpose. But recently, I was able to devise a way around it which I would like to share:
//Snippet
var k = 0;
var rows = new Array(4);
var cols = new Array(4);
var multiArray = new Array(rows, cols);
//initialization of values
for(var i=0; i<4; i++){
for(var j=0; j<4; j++){
multiArray[i][j] = ++k;
}
}
//prints out values into HTML body in a web browser
for(var i=0; i<4; i++){
for(var j=0; j<4; j++){
document.writeln('
'+multiArray[i][j]);
}
}
I believe the code snippet is easy to comprehend and use. A simple guide:
The 'cells' are initialized with values using loop construct. And in the second loop block the values will be displayed into the body of a webpage.
But it's interesting to know that JavaScript doesn't yet have an inherit way of programming multidimensional array. This
implementation and any other that you might come across won't support many of the properties and methods like implementation in strong type languages (C++, C#, etc).
Hopefully, there would be a library that will support all the features of multidimensional array implementation in JavaScript.
I'd like to attend to your questions, if you've any.
modified 22-Jun-16 8:31am.
|
|
|
|
|
Maybe because you misspelled "success" as "succsess" ?
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
|
Hi All,
I am working on computing Xor operation, but i could not exactly compute the proper result. Please help me to find a solution.
If we "true" and "false", how to compute XOR operation to get the final result?
I have tried like:
result = s1 ^ s2; // here s1= "true", s2= "false"
Regards,
Amal Raj
|
|
|
|
|
What do you mean by 'compute'? XOR is a standard operation and will return the defined result in all cases; i.e. TRUE when inputs are different, and FALSE when they are the same.
|
|
|
|
|
AmalRaj@Sync wrote: I could not exactly compute the proper result I assume you got 1 as the two operands of XOR are different, but What have you expect?
XOR (^) is a bitwise operator, so assigning it on other types (like Boolean or String) can have interesting results. The reason of course is how type casting is done...
For instance "hello" ^ "word" will return 0 (both operands are the same?), the reason is that both operands are converted to numeric and yielded NaN...and NaN is the same as NaN...
As in your sample true converted to 1 and false to 0, so 1 ^ 0 yields 1...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
Strings are not booleans or numbers. If you use:
var s1 = "true";
var s2 = "false";
var result = s1 ^ s2;
you will (correctly) get a result of 0 . This is because the strings are "truthy" - when converted to a boolean, all non-empty strings convert to true .
Truthy and Falsy: When All is Not Equal in JavaScript[^]
If you use proper boolean values, you will get the expected result:
var s1 = true;
var s2 = false;
var result = s1 ^ s2;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'd like to find a tutorial or code to learn how to do this: on a web page user enters text to search, then checks checkbox to indicate which fields to search.
* Testing should work in Firefox without installing anything else on my PC. Someone told me AJAX has some problems which disappear if run on a server, and I don't have access to a server with AJAX.
* I don't know if jquery would help me here or not. I know nothing about it.
* Find tutorials about filtering with XML, but not where they get user input from a form.
Screenshot of idea is here[^]
XML file is here:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="studies1.xsl"?>
<studies>
<!-- There is only one study in this example but
in real life there could be 500+.
-->
<study>
<authors>
<author>
<authorfname>Bill</authorfname>
<authorlname>Smith</authorlname>
<association>University of Foo</association>
<assocdept>Microbiology</assocdept>
</author>
<author>
<authorfname>Sandy</authorfname>
<authorlname>Green</authorlname>
<association>University of Foo</association>
<assocdept>Microbiology</assocdept>
</author>
<author>
<authorfname>Peter</authorfname>
<authorlname>Billowsails</authorlname>
<association>United Nations</association>
<assocdept>FAO</assocdept>
</author>
</authors>
<studytitle>How nematodes affect corn crops</studytitle>
<abstract>
These are usually several paragraphs long.
</abstract>
<tags>
<tag>corn</tag>
<tag>nematodes</tag>
<tag>IARC</tag>
</tags>
<publishdate>2016-02-03</publishdate>
<notes>Interesting study.</notes>
</study>
</studies>
I enclosed all the XML in pre and /pre tags and it still doesn't show. What am I doing wrong here?
modified 10-Jun-16 9:56am.
|
|
|
|
|
What architecture are you planning to use? MVC ?
|
|
|
|
|
Dear all,
I want show a picture fullscreen with one web page, but most of the web browers have address bars, toolbars and tab bars, I want show the picture without them all. For example, I use Chorme browser. How to implement it with JavaScript or other methods ?
Thanks all
|
|
|
|
|
In browsers that support it[^], you can use the fullscreen API:
And anticipating your next question, no, there is no way to launch fullscreen mode without asking for the user's permission.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard,
It's very kind of you, thanks a lot, I'll do some tests and feedback later.
Thanks
|
|
|
|
|
Hi Richard,
Thank you once again, I have tried the API,it works and very useful for me. But not reach my goal, as you say there's no way to lanuch fullscreen mode without asking for the user's permission. I have tried to set the state of the key clicked when load the page, so that it can trigger fullscreen mode when open the page, but it does not work in this way. My goal is to show a photo on the screen like desk background pictures, and some other info like Date, temperature and so on.
For the device, may be I can ues Raspberry pi or my old computer.
For my goal, it's not only like a project of digital photo frame, but also a smart home controller.
First of first, show the photo with fullscreen, maybe I should try another solution, can please give me some suggests?
Thanks
B/R
Jiang
|
|
|
|
|
As I said, you cannot enter fullscreen mode without the user's permission.
If there was a way around that restriction, I'm sure every scam, malware and porn site would be doing it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I need simple Javascript code to "Revert To Saved" a fillable PDF form.
Thanks!
|
|
|
|
|
|
- Using Firefox v43.
- Trying example at Simple and Practical Introduction to Asynchronous JavaScript and XML (AJAX)[^]
- I'm a newbie here and with Javascript. If this isn't the right site for newbies just let me know. Some sites are somewhat hostile to newbies.
- I do have Ublock Origin in FF, I don't know if that or FF is blocking popups or not. If so, how do I get FF to not block popups from local HTM files?
I made the XML file and html file (which I called ajax1.htm) and opened it in Firefox. I clicked the button "ReadXML" and it did nothing, nothing changed in my browser.
I'm trying to figure out if FF does not support XMLHttpRequest or if something else is going on. Do you have any ideas?
EDIT: The bottom of ajax1.htm has been changed to this to test the Error() function via clicking a new button. I got no result from clicking the "Test error" button either. (The code formatting does not seem to be working.)
</script>
<script type="text/javascript">
function testButton() {
Error("This is an error");
}
</script>
<body>
<span id="xmlSpan"></span>
<input type="button" onclick="ReadXmlFile();" value="ReadXml" />
<input type="button" onclick="testButton();" value="Test Error" />
modified 25-May-16 15:14pm.
|
|
|
|
|
1. The link you posted is to an article. Usually if you have a question about the article you post it at the bottom of the article. In this case I think it's still valid that you asked here.
2. Notice the date on that article, 2009. Quite old in tech years. I suggest using jQuery and calling .ajax() instead. There are tons of examples online and jQuery is a library that keeps up with the various browsers so the same code should work in all browsers.
3. See jQuery.ajax() | jQuery API Documentation[^] for documentation.
4. Also, if you choose to stick with your original question, edit it and post the relevant code.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
When you have a question about code in an article, it's usually best to post it in the forum at the bottom of the article[^]. That way, the author will be notified of your question and have a chance to respond. The person who wrote the code is the person most likely to be able to answer your question.
Are you loading the page from a web site, or just double-clicking on the HTML file in Windows Explorer? You might have problems making AJAX requests work in a local file.
Have you tried checking the Web Console[^] (F12) for error messages?
Firefox definitely supports the XMLHttpRequest :
XMLHttpRequest[^]
Can I use... XMLHttpRequest advanced features[^]
Error isn't a built-in function, and doesn't appear to be defined in the article's code. Try using alert instead:
function testButton() {
alert("This is an error");
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|