|
use case/switch statement
switch (true) {
case (age == 21):
alert(" equal");
break;
case (age> 21):
alert(" older");
break;
case (age < 21):
alert("younger");
break;}
|
|
|
|
|
<script>
function myfun() {
var age = 21;
(age < 21) ? alert('less than 21') : (age > 21) ? alert('greater than 21') : (age == 21) ? alert('equl 21') : alert('else part');
}
</script>
It's give you result 100% with single line.
|
|
|
|
|
The third expression "age == 21" is redundant. If it is not less than and not greater than then there is only one other value it can have.
|
|
|
|
|
Godhaniketan wrote: Hello Richard MacCutchan,
I think you have not tested well in my case it's worked fine. i think you should have to check again.
if any doubt then reply me.
just change value of age like 19,21,22 and 'blah..' it gives you all kind of alert..please try it out. Well I guess you do not understand that simple statement only requires two if parts.
If age is less than 21 : Alert1
If age is greater than 21 : Alert2
Else: age must be equal to 21, so the test for equality is not needed.
modified 21-Jul-15 9:22am.
|
|
|
|
|
Godhaniketan wrote: Hello Richard MacCutchan,
have you read question of "Member 11849688" he written clearly that "else if age==21 alert" that means he/she wants alert on equality condition also.
please read out the question properly.
he/she want 4 alert <, >, ==, else part. Yes, and that is what my logic provided. If you really cannot understand simple boolean expressions then ...
modified 21-Jul-15 9:23am.
|
|
|
|
|
Yes i understand your logic..
i will remove redundancy.
thanks
|
|
|
|
|
And in future, please do not remove messages as you have done here. We all get things wrong from time to time (me more often), so just be adult enough to accept correction.
|
|
|
|
|
How do I send a user to another webpage by opening it up in a new tab?
Here's what I know so far:
location.href="addurlhere"
I am at the very beginnings of learning, but I do not want people leaving my page completely to check out another, does that make sense?
Thank you!
|
|
|
|
|
<script type="text/javascript">
function OpenInNewTab() {
window.open('http://localhost:2319/test.aspx', '_blank');
};
</script>
<div onclick="OpenInNewTab();">test</div>
|
|
|
|
|
I have a code for which the is on right of page. it is fixed there by css as follows:
#feedback
{
position: absolute;
width: 230px;
float: right;
height: 60px;
right: 310px;
top: 190px;
}
but when the window size is resized the cs property 'right' should also reduce as this div is not visible if window is minimized than 100%
Initially
`$( window ).width() = 1899px;`
'right' property for feedback div should be 310px
For every reduce of 10px in window width, right css of feedback div should reduce by 4.5px
egg.
Width = 1899px Right property = 310px
Width = 1889px Right property = 305.5px
Width = 1879px Right property = 301px
.
.
.
.
util
Width = 1234px Right property = 0px
I'm not able to make this logic work. Can anyone please help
|
|
|
|
|
Please Provide me Book or Link which Covers Following Topics:
1. HTML/HTML5
a. HTML Page design using DIV based layout (no tables)
b. META Tags
c. Viewport
d. HTML5 Page design using <header>, , , and
2. CSS
a. Styling of elements using CSS
b. CSS properties – float, align, background, margin, padding, position, width, height
c. Pseudo classes
d. How to override CSS properties
e. Inline, embedded and external CSS
3. JavaScript
a. DOM Manipulation
i. Change content of the DIV based on some event
ii. Populate data inside a DIV using AJAX
iii. Show/Hide Elements
b. Event handlers
c. Timer functions – setTimeOut, setTimeInterval
d. AJAX and JSON
e. Cookies management
f. Debugging using Browser Console
g. JavaScript/CSS minification
Please suggest me link for the topics which are in bold letters.(Link/Book should cover Bold Marked Topics Mandatory.) Please reply asap.
|
|
|
|
|
|
www.w3schools.com/js/default.asp
|
|
|
|
|
I'm having a feedback box, which has to be at the right corner of the page and should scroll up and down with the scroll bar. But how to stop its flickering in IE and chrome CSS for that div is:
#showSurvey
{
position: relative;
width: 230px;
top: 190px;
float: right;
height: 60px;
}
and javascript to keep it at top is
var wintop = $(window).scrollTop(); if(wintop >= 190) {$('#showSurvey').css('top', (wintop + 10));} else{
$('#showSurvey').css('top', '190px');
}
Using this the div flicker a lot and it looks ugly can anyone please help
|
|
|
|
|
You need a trigger loaded on DOM Ready, to fire a function
So when the viewport changes, the trigger fires a function that changes the position of the box in the upper right corner.
So there are several bindings here. It took me awhile to figure out how to handle multiple events.
$("#txt_ac_state") is a hidden textbox that holds the state of the box, if the box is a tab on the right, or fully displayed.
$("#div_adContainer") is your box.
build_adContainer is a function that creates my box dynamically on the fly.
It's a really long piece of code to post, so I just posted the basics mechanics of my thought.
[Edit] Whoops, I posted the first prototype, this was the final bind code.
$(document).ready(function () {
viewportWidth = $(window).width(); viewportHeight = $(window).height; ac_state = 1;<br />
initiateBinding();
var $scrollingDiv = $("#div_adContainer");
$(window).scroll(function () {
$scrollingDiv
.stop()
.animate({
"marginTop": ($(window).scrollTop())
}, "fast");
});
});
function initiateBinding() {<br />
if (false === is_mobile_device()) {
build_adContainer();
window.addEventListener("resize", winResize);
document.body.onresize = bodyResize;
}
else {
build_adContainer_Moblie();
}
}
function winResize(e) {
viewportWidth = $(window).width(); viewportHeight = $(window).height;
obj_width = 180; obj_height = 612; obj_start = viewportWidth + obj_width;
ac_state = $("#txt_ac_state").val();
if (ac_state === "1") {
obj_x = viewportWidth - obj_width; obj_y = 150;
$("#div_adContainer").css('left', obj_x + 'px');
}
else {
obj_x = viewportWidth - 32; obj_y = 150;
$("#div_adContainer").css('left', obj_x + 'px');
}
e.stopImmediatePropagation();
}
function bodyResize(e) {
viewportWidth = $(window).width(); viewportHeight = $(window).height;
obj_width = 180; obj_height = 612; obj_start = viewportWidth + obj_width;
ac_state = $("#txt_ac_state").val();
if (ac_state === "1") {
obj_x = viewportWidth - 32; obj_y = 150;
$("#div_adContainer").css('left', obj_x + 'px');
}
else {
obj_x = viewportWidth - obj_width; obj_y = 150;
$("#div_adContainer").css('left', obj_x + 'px');
}
}
The intention of the posted code samples is for you to get a better idea of how to move your box without flickering, and to detect changes that you have not anticipated yet.
Your going have to figure out it out on your own how to implement your new code, but just take it one step at a time.
|
|
|
|
|
Thanks , but when the browser width is minimized this div overlaps other content.
I want this div to stay at its place and be visible if the the scroll it taken to its right.
Can you suggest ? plz
|
|
|
|
|
You said you wanted to fix the flicker.
The code was for reference only, fix or adjust the code to the positions you want.
|
|
|
|
|
Hi,
I have about
12 rows and each row contains 2 textboxes eg txtRateFrom txtRateTo.
Obviously, each textbox has a different name but it will always contain txtXXXFrom and txtXXXTo.
<table class="style1">
<tr>
<td>
<asp:TextBox ID="txtRateFrom" runat="server" </asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtRateTo" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtYieldFrom" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtYieldTo" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtCalFrom" runat="server"></asp:TextBox></td>
<td>
<asp:TextBox ID="txtCalTo" runat="server"></asp:TextBox></td>
</tr>
The fields aren't required and user doesn't have to fill in any textbox or he can fill in just one textbox. If he fills in To he doesn't have to fill in From.
The range he can enter in the textboxes are from 0-100. So I assume that if he only enters a To number the From value is 0.
If he enters From number only I assume the to is 100.
I need to do a few validations.
Make sure only integers are entered as soon as user types text in the textboxes.
Check that it's in the correct range. User can't enter for example 101.
And make sure that the To field is bigger than the From field.
I need to show the user messages regarding the relevant error inside a validationsummary and also show * next to the td where the error occurs. If the error occurs for example in the txtratefrom textbox then next to Rate td i need to show Rate *.
What is the most efficient way of doing this?
Thanks
|
|
|
|
|
Custom Validation is better for this kind of validation at clientside
|
|
|
|
|
Thanks. I know and this is what I am trying to do now. But I am unable to. How can I do this with customvalidation client side?
Thanks
|
|
|
|
|
I created a simple function
Greet (),
What goes inside the ()? If I leave it blank, when I call the function it works great. If I put something inside then it stops working altogether, even when I put the same thing inside.
I'm happy it worked, but I'm very new to this and want to understand fully the basics. Thank you so much for your help!
|
|
|
|
|
These links can give you an overview about JavaScript functions basics:
|
|
|
|
|
I just learned this myself. When you define your function Greet(), you need to define it with something inside the parenthesis so the function expects to get data to then be used in the function. So you would define Greet() instead as Greet(var). In this case var is any variable name you choose. Greet can then use var in the function for whatever purposes it needs. When you call Greet, you would put a string or other variable name inside the parenthesis: Greet("Sue") or Greet(namex). The function will then treat that as var. Hope that was clear enough to help!
|
|
|
|
|
I have created a small web app using HTML5 + AngularJS to upload custom files(such as with extension .xyz). It works fine on Desktop browsers(IE, Firefox, Chrome). However on mobile browsers, it fails to detect the file and gives ‘Unsupported file format’ in android and iPhone only gives an option to select images. Is there a way we can upload the custom(.xyz) files using ‘input’ element with type=file? How can I make file upload mobile browsers compatible?
Praveen Raghuvanshi
Software Developer
|
|
|
|
|
I was using Blob to save a file.
var blob = new Blob([output], { type: "text/plain;charset=utf-8" });
saveAs(blob, "FileName.csv");
It stopped working in IE 11 for some reason on multiple computers. It still works in other browsers.
My question is either, 1) how can I get Blob working again in IE or 2) is there another way to save a file without using Blob?
Thanks
Brent
Brent
|
|
|
|