|
|
I am developing a web upload page in asp.net. Here I am providing interface to select different files as in thisfig.
It works properly. Here I have provided option to remove wrong file selections before uploading. But if I click on second or 3rd button all the selected images(1,2,3) gets deleted from page instead of respective selection.
This is the function I have given to button click,
function attachmentremove()
{
var browse = document.getElementById("FileUpload");
var newbrowse = browse.cloneNode(false);
browse.parentNode.replaceChild(newbrowse, browse);
}
I have given 3 different functions for different button click.
How to solve this error ?
|
|
|
|
|
I am trying to change the webpage background based on the user preferences, they have at the moment 5 background images to choose from.
When they click the background image that they want, the code-behind saves the image to a user preferences table in SQL and also updates the users cookie, when the master page is loaded a call to the cookie is made to get the image.
Public MyBg as string
MyBg = "css/image/" & Request.Cookies("tmr")("bgi")
In Code-Behind Master Page, and On the page I have
<pre lang="Javascript"><script type="text/javascript">
window.onload = function () {
function load() {
$('#content').css('background', '#000 url(' + <%=MyBg %> + ') center');
}
}
</script>
If I view the page source code on a rendered page I can see
<script type="text/javascript">
window.onload = function () {
function load() {
$('#content').css('background', '#000 url(' + css/image/ecb.jpg + ') center');
}
}
</script>
All looks good apart from the fact NO image is in the background, can anyone help with this?
|
|
|
|
|
Well, it doesn't look good. If you check the error console, you'll see an "unterminated string literal" error, because your background path is outside of the Javascript string.
Your onload event handler also declares a nested function to set the background, but never calls it.
Change your code to:
window.onload = function() {
$('#content').css('background', '#000 url(\'<%=MyBg %>\') center');
};
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
at last it is working, thank-you so much, only spent 4 hours on this simple task.
|
|
|
|
|
Hi, I have been given the task of teaching JS to non-techies.
I think Sublime 3 looks good.
I think JSHint / Gutter linter looks good.
Q1. Are these products easy to use by newbies?
Q2. Does anyone know how these products (Sublime and JSHint) can be installed on a usb drive so that it is truly portable and can be mode from pc to pc or classroom to classroom or home?
Students don't have the ability to install software in campus computers.
Much thanks,
David
|
|
|
|
|
|
A1. No. It is even more interesting, how a text editor and a style-cop library related to teaching JavaScript to non-tech person!!! Teach them basics of JS, based on some JS tutorial...If you need personal code space use some online tool, like TutorailsPoint's CodingGround or jsFiddle...
A2. It very depends on security policy on the campus, but theoretically, you can load anything from a disk-on-key drive...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
I've been working on this for a couple of hours. I have a confirm, and it always returns false no matter which button you click.
I tried it on Windows Firefox, Edge, Chrome, and IOS Safari, Chrome and it works fine.
I ran some test to see if the code is running to the end, but it's not. In VS2015 there are no errors, edge using F12 no errors.
I'm scratching my head on this one.
var _confirm = confirm('Are you sure you want to delete the section ' + _name);
alert(_confirm);
if (confirm) {
}
|
|
|
|
|
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
|
|
|
|
|