JavaScript - String Comparison Operation
are these right ya?
'3' !=='smith' true "test" == "test " true '2' != 'smith' true "exam" == "Exam" true 5 === "5 " false "t" > "T" false "y" >= "p" true "Happy" == "happy " true Similar Tutorials<script type="text/javascript"> function disp_confirm(){ var name=confirm("Are you sure that you want to do this?") if (name==true){ perform database delete here }else{ document.write("Cancel!") } } I'm not sure whether this can be done, but can I perform a database delete where indicated? Can you suggest a code snippet so I can see the style? Thanks for your help. hi, how I can execute this operation : for example x=a+b where "a" it can have value 0 or 1 based on the selection of the radio button. when a user select 1 on the radio button x=1+b when user select 0 x=0+b . please help me. HI, we suppose of being able to choose on a various menu drop down functions, for example: pippo=a+b pippa=a-b cippa=a*b zippa=a/b using a menu drop down for the choice of the operation pippo, pippa,cippa,zippa, how I could make this script . PLease help me Hello guys, I've made a music playlist where you should be able to listen to music (of course). All works fine, i am capable too listen to all the music in my playlist. But, when i reload my website and click on a song, it send me an error message - "Adobe Flash Player has stopped a potentially unsafe operation. If you want the program to communicate with Internet, click on settings." When i click on settings, i get another message - "Sorry, this page is not available". I had also another Option instead of settings which where, "ok". When i click on OK it works fine and it's no problem to scroll through the musiclist and listen to all of the soft songs. But i don't even want the message to appear from the very first time. Do you know what i should do to get rid of the message? Here's my code: Code: <!-- BEGIN JAVASCRIPT PLAYER EMBED CODE --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script> <div id="player-holder"></div> <script type="text/javascript"> var options = {}; options.playlistXmlPath = "playlist.xml"; var params = {}; params.allowScriptAccess = "always"; swfobject.embedSWF("OriginalMusicPlayerPlaylist.swf", "player-holder", "250", "250", "9.0.0",false, options, params, {}); </script> <!-- END PLAYER EMBED CODE --> Regards Webjoker Why alert('hua'); does not pop up ? Code: var cur_date = new Date(); cur_date.setSeconds(0); cur_date.setHours(0); cur_date.setMilliseconds(0); cur_date.setMinutes(0); alert(cur_date); alert(new Date(cur_date.getFullYear(),cur_date.getMonth(),cur_date.getDate())); if (new Date(cur_date.getFullYear(),cur_date.getMonth(),cur_date.getDay()) == cur_date ) { alert('hua'); } I'm trying to get an emerge effect using javascript. Here is my code Code: var t; var s=0; function emerge() { document.getElementById('my_span').style.opacity=s; s=s+0.1; t=setTimeout("emerge()",250); if (s>1) { clearTimeout(t); } } } Works fine, does the things right. But if I use this code, I get error. Code: var t; var s=0; function emerge() { document.getElementById('my_span').style.opacity=s; s=s+0.1; t=setTimeout("emerge()",250); if (s==1) { clearTimeout(t); } } } The only thing I changed was comparison operator. I tried to debug by adding alert box Code: var t; var s=0; function emerge() { alert(document.getElementById('my_span').style.opacity); document.getElementById('my_span').style.opacity=s; s=s+0.1; t=setTimeout("emerge()",250); if (s>1) { alert("Opacity set to max"); clearTimeout(t); } } } For some reason, it does not enter the if block if I use "==" operator & the alert box keeps coming up with "1" in it. But works fine if I use ">" operator, enters the block and the last value it shows is "0.9". Can anyone explain as to why this happens? I would like to compare dates in the format used in twitter, which is this: Wed Apr 08 14:30:10 +0000 2009 How do I do this? Do I need to convert to a timestamp first, and if so, how do I do this? G Hello, I try to learn JavaScript and I've just come across something that I can't work out. I use the book of John Pollock: JavaScript, A beginner's guide, Third Edition. So, page 360 and this piece of code: Code: function getname() { var the_text=window.prompt("Enter your first and last name",""); if (the_text.indexOf(" ") == -1) { window.alert("Put a space between your first and last name. Try again."); getname(); } var split_text= the_text.split(" "); if ((split_text[0].charAt(0) != "Z") || (split_text[0].charAt(0) != "z")) { var shorter_fn_string = split_text[0].substring(1,split_text[0].length); new_fn_name = "Z"+shorter_fn_string; } else { var shorter_fn_string = split_text[0].substring(1,split_text[0].length); new_fn_name = "W"+shorter_fn_string; } if ((split_text[1].charAt(0)!= "Z") || (split_text[1].charAt(0)!= "z")) { var shorter_ln_string= split_text[1].substring(1,split_text[1].length); new_ln_name="Z"+shorter_ln_string; } else { var shorter_ln_string= split_text[1].substring(1,split_text[1].length); new_ln_name="W"+shorter_ln_string; } window.alert("Now your name is "+new_fn_name+" "+new_ln_name+"!"); } getname(); the thing is it ain't working. If I type in the propmpt window let's say simon simon I will get an alert of zimon zimon but if I type in zimon zimon it won't change to wimon wimon. I suppouse it's because of != comparison operator. If I use == instead of != and change the code the other way round inside if block then it works. Code: function getname() { var the_text=window.prompt("Enter your first and last name",""); if (the_text.indexOf(" ") == -1) { window.alert("Put a space between your first and last name. Try again."); getname(); } var split_text= the_text.split(" "); if ((split_text[0].charAt(0) == "Z") || (split_text[0].charAt(0) == "z")) { var shorter_fn_string = split_text[0].substring(1,split_text[0].length); new_fn_name = "W"+shorter_fn_string; } else { var shorter_fn_string = split_text[0].substring(1,split_text[0].length); new_fn_name = "Z"+shorter_fn_string; } if ((split_text[1].charAt(0)== "Z") || (split_text[1].charAt(0)== "z")) { var shorter_ln_string= split_text[1].substring(1,split_text[1].length); new_ln_name="W"+shorter_ln_string; } else { var shorter_ln_string= split_text[1].substring(1,split_text[1].length); new_ln_name="Z"+shorter_ln_string; } window.alert("Now your name is "+new_fn_name+" "+new_ln_name+"!"); } getname(); Why is that? Regards, Simon My code isn't working, the only part that is showing up in the webpage is the head. Can someone tell me what I am doing wrong. I typed it right out of the book; the way the book tells me to write it. Thank you. Code: <!DOCTYPE HTML> <html> <head> <title>Comparison Operators</title> </head> <body> <h1>Comparison Operators</h1> <script type="text/javascript"> var conditional Value; var value1 = "Don"; var value2 = "Dave"; value == value2 ? document.write( "<p>value1 equal to value2: true< br />") : document.write( "<p>value1 equal to value2: false<br />") value1 = 37; value2 = 26; conditional value = value1 == value2; document.write("value equal to value2: " +conditionalValue + "<br />"); conditionalValue = value1 != value2; document.write("value1 not equal to value2: " +conditionalValue + "<br />"); conditionalValue = value1 > value2; document.write("value1 greater than value2: " +conditionalValue + "<br />"); conditionalValue = value1 < value2; document.write("value1 less than value2: " +conditionalValue + "<br />"); conditionalValue = value1 >= value2; document.write("value1 greater than or equal to value2: " + conditionalValue + "<br />"); conditionalValue = value1 <= value2; document.write(value1 less than or equal to value2: " + conditionalValue + "<br />"); value1 = 21; value2 = 21; conditionalValue = value1 === value2; document.write( "value1 equal to value2 AND the same data type: " + conditionalValue + "<br />"); conditionalValue = value1 !== value2; document.write( "value1 not equal to value2 AND no the same data type: " + conditionalValue + "</p>"); </script> </body> </html> i have an iframe on my webpage and i am loading appropriate page in it by clicking appropriate button but when user logs out and at that time some page is opened in iframe corresponding to the login pages(like "edit profile") of user then at that moment i want to know that what page is loaded in iframe so that i close it(if it corresponds to pages of login like "edit profile") as user logs out and if it does not correspond to login pages then it remains as it is.For doing that i must know that what page is loaded in iframe and compare it in " if(condition){statement} in logout function" with the logion pages so that i know that if any of them is loaded in iframe and if loaded then close it.Can you help me with that by giving exact code example. Hello everyone, for starters, I'm NOT working with arrays...with that being said, I need your help...I created a webform in PHP that retrieves values from a mysql table and displays them with its own mysqli_fetch_array command, in that loop it generates a textbox for each record...so far so good. The created textbox (input element) is so that the user can type in the sequential number of how to reorder the records...example Original Order of Records 1 Alpha 2 Bravo 3 Charlie 4 Delta 5 Echo and user needs it to be in this order User input sequential 2 Alpha 5 Bravo 1 Charlie 4 Delta 3 Echo the new order of the records will be saved on a temporary table in the database before insertion on the main table, kinnda like a preview for the new order, something like this: New Order of Records 1 Charlie 2 Alpha 3 Echo 4 Delta 5 Bravo Now what I need is a function that helps me display a message if the user duplicates a sequential unique, if they type in number 1 in 2 or more records, when I hit the button for the preview I need it to loop through all the input boxes and check their values, compare it with the other inputs and determine if there are duplicates or not....if there're no duplicates, continue with PHP code.....if there are duplicates, display an error so the user seeks for the duplicate and change it (inputs left in blank will not be considered for the insertion in the preview table) I already have this: Code: function checkall() { const t='texto'; var contar=<?php echo $contar; ?>; var text = "" var conta = 1; var contas= conta+1; text = t+conta; texto = t+contas; //var curElement = document.activeElement.value; var cv=document.forms['OrderPreview'][text].value; //var cv=document.forms['OrderPreview'][curElement].value; do { //var cv=document.forms['OrderPreview'][text].value; if (document.forms['OrderPreview'][texto].value=="") { return; } if (cv==document.forms['OrderPreview'][texto].value) { alert("Something Bad"); } conta++; contas++; text = t+conta; texto = t+contas; } while (conta<=contar) } Btw, the document.activeElement part of the code displays me "undefined" in the alert message, I still don't have a clue why, could you guide me with this please? I can't do but compare the 1st input with the rest of the fields, OR compare one field to the inmediate next field....it's driving me nuts Any help will be truly appreciated, thanks in advance Hey all, I have a simple example below showing how when I pass in the value of the value attribute of option node, and then use if operator to check whether parameter is a string or not, even though it's a string, it converts it to false boolean and triggers the else statement rather than calling a function: Code: <body> <select> <option value="createMsg">Add Message</option> <option value="removeMsg">Remove Message</option> </select> </body> Code: var menu = { handleMenu : function(callback){ if(callback === "string"){ menu[callback](); } else { console.log("Issue occurred") } }, createMsg : function(){ var content = document.createTextNode("Please give additional information."), heading = document.createElement("h1"); heading.appendChild(content); document.body.appendChild(heading); }, removeMsg : function(){ } } document.getElementsByTagName('select')[0].onchange = function(){ menu.handleMenu(this.value)}; callback should be a string so why is it saying otherwise? Thanks for response I have a drop down menu where people can select a month, day and year. Based on their selection, I want to show them an image. If their selection is >= July 26, 2010 but <= July 25, 2011, show the red image; If their selection is >= July 26, 2011 but <= July 25, 2012, show the white image; If their selection is >= July 26, 2012 but <= July 25, 2013, show the blue image; If their selection is >= July 26, 2013 but <= July 25, 2014, show the yellow image; I don't know how to compare a selected date to a range of dates like this. I need help with the following code below. It just doesn't turn out okay. Any ideas? Code: function changing() { A = document.exempel.Amount.value B = ("<%#Container.DataItem("Price_2_qty")%>") C = ("<%#Container.DataItem("Price_3_qty")%>") D = ("<%#Container.DataItem("Price_4_qty")%>") E = ("<%#Container.DataItem("Price_5_qty")%>") if (A < B) {document.exempel.Price.value = "<%#Container.DataItem("Price_1")%>"} else if (A = B && (!(A >= C))) {document.exempel.Price.value = "<%#Container.DataItem("Price_2")%>"} else if (A = C && (!(A >= D))) {document.exempel.Price.value = "<%#Container.DataItem("Price_3")%>"} else if (A = D && (!(A >= E))) {document.exempel.Price.value = "<%#Container.DataItem("Price_4")%>"} else if (A >= E) {document.exempel.Price.value = "<%#Container.DataItem("Price_5")%>"} } I was looking at this page, and came across "%" used in strange context. It appears that the mod operator can be used in Strings?? http://download.oracle.com/javase/tu...vaOO/enum.html What does this do/ mean? Thanks!!: System.out.printf("Your weight on %s is %f%n", p, p.surfaceWeight(mass)); This is probably easy if I knew Javascript. Can someone show me the code to get the number "800014352" part from the url???? http://testebiz/ebizbtest/ShoppingCa...2/Default.aspx I am trying to use some string functions with no results. It appear what I'm using them on are not strings. my_string = document.getElementById("link5").onclick; document.write(my_string.lastIndexOf("5")); This gets nothing! And document.write(document.getElementById("link5").onclick.lastIndexOf("5")); gets nothing. BUT if I make a string and put what the onclick is set to with: my_string = "function onclick(event) { reveal(\"5\", \"2\", \"1864\")"; then my_string.lastIndexOf("5") will yield 34. So why is my original my_string = not working? And how can I get it to work? When comparing an empty string "" to another string like "1232", javascript is returning true. Why is that?
I have an array: Code: var array_123=["test1","test2","test3"]; I have a string: Code: var array_string = "array_" + "123"; I would like to use the value of array_string (array_123) as an array to parse out the values of it. But this isn't working: Code: for (var x in array_string) { var test_ary = array_string[x]; } Any help? |