Javascript Case Statement
Mar 3, 2006
I am writing some javascript code and just wanted to check if a case statement could have OR / AND. If yes, what would the syntax be like.
What I need is this:
switch (country) {
case "US" || "Canada":
//do something
break;
case "Australia" || "UK":
//do something
break;
}
I can alternatively use IF statement but was curious.
View 2 Replies
ADVERTISEMENT
Sep 14, 2010
how to get this functionality going. I have a div name "footer". Within "footer" I have 4 links:
link1, link2, link3, link4
Is there anyway to write a function which will sense which link was clicked and then alert the id of that selected link. I have written the code but am not certain why isn't it working. here is my code.
$('#footer a').bind('click', function(){
//alert($(this).attr('id'));
var mId = $(this).attr('id');
switch(mId)
[Code]....
View 4 Replies
View Related
Apr 16, 2007
So I have some code like:
if (document.Insurance.State.selectedIndex == 1)
{
ifIll();
}
else if (document.Insurance.State.selectedIndex == 2)
{
elseKan();
}
else if (document.Insurance.State.selectedIndex == 3)
{
elseInd();
}
I am trying to replace the if-else statements with case statement as
follows:
var index = document.Insurance.State.selectedIndex;
switch (index)
{
case 1:
ifIll()
break
case 2:
elseKan()
break
case 3: elseInd()
break
}
This code doesn't work ! Am I missing something here?
View 17 Replies
View Related
Mar 3, 2006
I am looking at a line of code in javascript that I dont understand...
var ad = n % nn;
What I dont understand is what the % represents as a mathmatical
function in javascript.
View 2 Replies
View Related
Mar 25, 2006
I have interrupted a login process (going to another interim page) to access the database and retrieve the zip code of the customer (don't ask :-). so they can agree or disagree (disagree is a javascript:back)
there are 3 $_post variables which i need to send on from within a confirm() to the login script.
Can this be done? They have to be $_post, rather than $_get
Is there a php alternative to the confirm? ( if so, i'm in the wrong place!!)
View 7 Replies
View Related
Jul 23, 2005
I am getting syntax errors in my JavaScript code, code snippet as follows
(between my <script></script> tags:
View 2 Replies
View Related
Apr 4, 2011
my webstie allows users to change the color of the background, so to keep the text readable I have it changing as well.the color picker I am using has text boxes with rgb values 0-255 for each.I am trying to get one bit of text to alternate between red and blue with the conditions
Code:
if(blue>green && blue>red)
{
[code]....
View 2 Replies
View Related
Feb 20, 2007
In Bourne shell, you can do:
case ($x) in
foo*)
;;
*bar)
;;
esac
so that the first case matches any string starting with "foo", the
second any string ending in "bar", etc. In Tcl, you can:
switch -glob $x {
"foo*" {
}
"*bar" {
}
}
and accomplish the same thing. I'm struggling to do that in
JavaScript. switch seems to follow C semantics and do a full-length
match. And String.match() doesn't seem to do glob-style matching so I
can't do:
if ($x.match("foo*")) {
...
Is there a way to match on patterns in a JavaScript control structure?
View 7 Replies
View Related
Feb 1, 2004
I'm working on developing an RSS/RDF/Atom Parser in JavaScript. I've already successfully implemented complete support for RSS 0.9x and 2.0. So far, so good. However, I've run into two minor problems. One is mentioned here, and one is in another post.
The issue that I'm coming across is the case-sensitivity of getElementsByTagName() when parsing standard RSS (XML) tags.
Danny Goodman's JavaScript Bible says that the tag name string that gets passed as the parameter in getElementsByTagName() is case-insensitive. However, this is speaking in terms of HTML and the HTML DOM. I'm working with XML, and getElementsByTagName is handling the XML tags as being case-sensitive.
Can someone suggest a way around this? Can a regular expression be used as the parameter? If so, what would the syntax be (as I'm not very familiar with regex)? For example, I want a <textinput> tag to be handled the same as <textInput> (which is the correct syntax).
View 11 Replies
View Related
Jul 20, 2005
Is this sort of thing possible:
var X = 'Moe'
switch (X) {
case 'Curly'||'Moe'||'Larry':
alert('Found one of the Three Stooges');
case 'Chico'||'Harpo'||'Zeppo'||'Grouco'||'Gummo':
alert('Found one of the Marx Brothers');
default:
alert('No matches');
This gives 'No matches' unless I only put a single string in the 'case'
lines. I've just been using VB's Select Case which is a similar flow
control but which allows conditional arguments in the 'cases'. I just
wondered...
I realise you could put each set of names in an array and iterate
through each array, but that's a different issue.
View 4 Replies
View Related
Jul 21, 2009
I'm experimenting with creating SVG dynamically and am finding that document.createElement is changing the case of the tags I input. This is breaking because, apparently SVG tags are case sensitive. For example, when I try to create a linear gradient element like so:var grad = document.createElement('linearGradient');what appears in the view source is:<lineargradient ...> (Note the lowercase "g")The tag doesn't work if the "G" is lowercase. Is there any way to specify in the <html> tag (or somewhere else) that the document should preserve tag case?
View 1 Replies
View Related
Oct 28, 2011
I would like to compare two arrays of characters...but the comparison should be case-insensitive i.e. A should match a...how can i do this?
View 1 Replies
View Related
Nov 19, 2010
So, I have a list of items that need to have a new preset list item appear based on what day it is. I have the date script working (to test, change the first case to some random date and change the third case to todays date - 10192010 - It will fire that document.write). What I need the cases to do though, is set the visibility of certain list items.
This is just an example, there will be around 20 list items in the final project. As you can see in the first two cases, I've tried a couple different routes to no avail.
The Code (class references are irrelevant to this example, they belong to the final project):
<html>
<head>
<script type="text/javascript" language="JavaScript">
/*
[Code]....
View 2 Replies
View Related
Jun 29, 2011
I need to manipulate with a upper and lower case on STRINGS
For example I have string: LALA_KAKA_mama_WIWI
I need to conwert it to Lala_kaka_mama_wiwi with first letter upper case.
Is it one simple way to do it with JS script/code?
View 1 Replies
View Related
Aug 31, 2009
I'm doing a bit of experimentation and would like a bit of advice if possible please.
In my switch statement I would like to use the || or operator, it works correctly it I set the case to 31, but if I try 1||31 it doesn't.code...
View 4 Replies
View Related
Apr 25, 2006
If I want to send something simple to the server and I don't need a response, instead of using AJAX, I use this:
<html>
<head>
<script type="text/javascript">
function sendToServer(someText) {
var fakeImg = new Image();
fakeImg.src = "http://localhost/takeparam.asp?param=" + escape(someText);
}
</script>
</head>
<body>
<input type="button" value="press me" onclick="sendToServer('baloney');" />
</body>
</html>
Is there anything inherently "wrong" with this? I know that it requires javascript enabled. As far as I can tell it will work on more platforms that AJAX so that should be a good thing, right?
View 7 Replies
View Related
Nov 29, 2010
I want to write a javascript that converts the (each) first character occuring after space in a string to lower case e.g abc def ghi jkl to abc Def Ghi Jkl
I have tried document.getElementByID and then checking for spaqce by putting the element in the Array but it does not work.
View 4 Replies
View Related
Nov 21, 2011
this is what im trying to do:
Code:
var field01 = document.getElementById("Field01").value;
field01[0] = field01[0].toUpperCase();
it doesnt work, the first letter of the field stays lower case BUT when I do this:
Code:
alert (field01[0].toUpperCase());
then it converts the first character to uppercase, well only in the alert box, the actual one still unchanged.
so i figure thats because it needs to be triggered somehow, it wont work by assigning it. i cant use it as return. are there any trigger methods that would just let me capitalize the first letter without any pop ups or anything?
View 14 Replies
View Related
May 15, 2009
I have the string in Javascript and now i want to make that string letter case. Means each first letter in caps of the string. for e.g. if following string is passed Is there any ready made function in javascript or can any one provide me reference for the same?
View 2 Replies
View Related
Jul 20, 2005
I'trying to use a regExp in Javascript to replace any all upper case word in a string by the same word having only its first letter in upper case.
This expression detects the words:
View 3 Replies
View Related
Mar 21, 2011
I am very new to jquery live function & i stuck in to the problem. I am using live function to get the ajax response & appending to the div here is my code,
function add_master(module_url, response_target_id, custom_id) {
$('a.addclass').live('click', function() {alert('add');
$(response_target_id).fadeIn('fast');
[code]....
View 4 Replies
View Related
Feb 5, 2009
I am putting together a simple edit in place script. For some reason, in order for for the editEffect function I've created to work I need to use the alert function as seen in the code below. I can't figure out the cause of the problem and I believe the root cause is also creating other problems - i.e. in the cancelEdit function the argument "targetElement" is not alerted, but it is successfully submitted as an argument to another function.
/* Edit in place javascript code */
function editLightOn(element){
element.style.backgroundColor = "#ffc";
}
function editLightOff(element){
element.style.backgroundColor = "#FFFFFF";
}
[Code]..
View 4 Replies
View Related
Oct 18, 2009
I am returning the present time - then using the .substr to remove all digits except the last two on the right (i.e effectively returning the value 32 from 65344532) I am then looping, subtracting 11 from that number until the value is less than 11. The intent being to then return the value from the appropriate matching array ID code...
The problem arises with evaluating two digit numbers beginning with zero - In cases where the last two numbers are greater than 09, the looping returns a 1 digit number for valuse less than 10, in cases where the last two digits begin with zero the loop will not begin. I have attempted to use the switch(n) to determine if any 01, 02, 03 ... etc exists but this is not evaluating correctly - is this due to using the date/time object and if so is there a good way to convert this to either a numeric or string datatype where the case can be evaluated correctly?
View 11 Replies
View Related
Jan 4, 2010
i need to enter either capital or small letter the input should be accepted.
The code is written below:
var Alphabet;
Alphabet= prompt("Enter an Alphabet");
if(Alphabet == "a" || Alphabet == "e" || Alphabet == "i" || Alphabet == "o" || Alphabet == "u")
[Code]....
View 2 Replies
View Related
Aug 22, 2010
It's well know that the ternary operator syntax is something like so:
Code:
(test) ? true doThis : false doThat
Suppose that in case condition is false we want do nothing. How to code "do nothing"? May I let it blank or there are an appropriate syntax?
View 10 Replies
View Related
Aug 25, 2010
problem with accessKey attribute value p (lowercase) and P(uppercase) for different html buttons.. the browser unable to differentiate between upper and lowercase key ...
i have a simple form with two buttons, and i want to trigger these buttons with keyboard keys in combination with Alt key. for example Alt + P (uppercase) should trigger button 1 and Alt + p (lowercase) should trigger button 2
Browser: IE 8.0
here is the code...
-----------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
[Code]....
here the behavior is strange, when i press Alt+P in keyboard, button1 is triggered and when i press Alt+Shift+P in keyboard, button2 is triggered ..
View 1 Replies
View Related