JavaScript - Translate From Asp To Javascript
I have 2 functions in asp that I need translated to javascript
the first checks that there is no email in the textbox. the second checks that there is no phone number can someone help me? here's the asp code Code: Function ExtractEmail(sText) Dim arrWords, x, curWord Dim sEmail, sName, sDomain Dim dotIndex, y 'remove any extra spaces sText = Trim(sText) Do Until InStr(sText, " ")<1 sText = Replace(sText, " ", " ") Loop 'split into words arrWords = Split(sText, " ") 'look for email, initialize return value sEmail = "" For x=0 To UBound(arrWords) curWord = arrWords(x) If LCase(curWord)="at" Then curWord = "@" End If If InStr(curWord, "@")>0 Then If (Left(curWord, 1)="@") And (x=0) Then 'ignore, start of sentence Else 'we got possible email! curWord = Replace(LCase(curWord), "dot", ".") If Left(curWord, 1)="@" Then sName = arrWords(x-1) Else sName = Left(curWord, InStr(curWord, "@") - 1) End If sDomain = "" If Not(Right(curWord, 1)="@") Then sDomain = Right(curWord, Len(curWord) - InStr(curWord, "@")) End If If (InStr(sDomain, ".")<1) Or (Right(sDomain, 1)=".") Then If x<UBound(arrWords) Then If Right(sDomain, 1)="." Then sDomain = sDomain & arrWords(x + 1) Else dotIndex = -1 For y=x+1 To UBound(arrWords) If (arrWords(y)=".") Or (LCase(arrWords(y))="dot") Then dotIndex = y Exit For End If Next If (dotIndex>x) And (dotIndex<UBound(arrWords)) Then For y=x+1 To dotIndex-1 sDomain = sDomain & arrWords(y) Next sDomain = sDomain & "." & arrWords(dotIndex + 1) End If End If End If End If If (InStr(sDomain, ".")<1) Or (Right(sDomain, 1)=".") Then sDomain = "" End If If (Len(sName)>0) And (Len(sDomain)>0) Then sEmail = sName & "@" & sDomain Exit For End If End If End If Next 'free allocated memory Erase arrWords ExtractEmail = sEmail End Function Function checkphone(sText) checkphone=false Dim arrWords, x, curWord Dim sEmail, sName, sDomain Dim dotIndex, y 'remove any extra spaces sText = Trim(sText) Do Until InStr(sText, " ")<1 sText = Replace(sText, " ", " ") Loop 'split into words arrWords = Split(sText, " ") 'look for email, initialize return value sEmail = "" For x=0 To UBound(arrWords) curWord = arrWords(x) curword=replace(curword,"(","") curword=replace(curword,")","") curword=replace(curword,"-","") ' response.Write curword & "<br>" if isnumeric(curword) then ' response.Write curwords & " is numeric<br>" if len(curword)>=9 then ' response.Write "<hr>" & curword & " is a problem<hr>" checkphone=true end if end if Next 'free allocated memory Erase arrWords End Function Similar TutorialsFirst of all, I read the rules regarding how to post a question on the forums, and I couldn't think of a much better description, so I hope thats okay. My problem is this, I am using a simple code (Posted Below) that creates a drop-down menu containing a list of languages, when any of these languages are clicked it sends the user to Google translate to automatically convert the text. The code works fine, but now Im realizing I have no way of knowing which languages are chosen and how often. I have tried linking it to my Google Analytics but to no avail. The only solution I can think of is to send the user to maybe a PHP file that then redirects them to the Google translate page, so I can monitor it by viewing how many times the redirect page was viewed. I already use this redirect technique to track how many users follow my links to external downloads, so I know its probable. But my real question is how would I go about sending the user to a redirect page? I'm a novice web developer by the way. I'm thinking I would have to send the variable containing language to the redirect, along with a variable containing the URL to be translated, and then have the redirect input the data same as the original form. But even if this is possible, I don't know how to go about it. Any help would be greatly appreciated. Quote: <select name="translate" style="height:18px; font-size:10px;" onchange="javascript:window.location = 'http://www.google.com/translate_c?hl=en&langpair=en%7C' + this.value + '&u=' + window.location.href;"> <option value="">Translate This Page</option> <option value="ar">Arabic</option> ...LIST OF OTHER LANGUAGES <option value="es">Spanish</option> </select> Hi, Is it possible that when a webpage loads I can have javascript change the class of a div from: .up { transform: translate(0px,-500px) transition: all 5s ease-in; } to .down { transform: translate(0px,0px) transition: all 5s ease-in; } Essentially I would like a div to move down into place from the top of screen to the middle of screen after the page has loaded. Some thing like this?: Code: <script type="text/javascript"> function transform() { document.getElementById("content").className = "down"; </script> <div id="content" class "up" onload="transform()"> </div> </html> would this work or is there a better way? Adrian. xcab any1 explain the following php code for me and tell me whats missing please: <form id="ContactForm" action="" enctype="multipart/form-data"> <div> <input type="text" onblur="if(this.value=='') this.value='Your Name::'" onfocus="if(this.value =='Your Name::' ) this.value=''" value="Your Name:"/> <input type="text" onblur="if(this.value=='') this.value='E-mail:'" onfocus="if(this.value =='E-mail:' ) this.value=''" value="E-mail:"/> <textarea onblur="if(this.value=='') this.value='Message:'" onfocus="if(this.value =='Message:' ) this.value=''" cols="25" rows="7">Message:</textarea> <p class="fright"> <a onclick="document.getElementById('ContactForm').reset()" href="#">Clear</a> <a onclick="document.getElementById('ContactForm').submit()" href="#">Send</a> </p> </div> </form> Hello, I think I am posting this in the right spot! I'm trying to add google translate to my mobile website... Because, I want an easy way for koreans to read it. It's a mobile site by dudamobile so my editing ability is limited.. the issue I am having is it works but it is throwing off my scrolling ability and page size and the toolbar and banner was spanning my webite to a very large area which threw off the look of the site. I was able to remove the banner (which I didnt need) by inputing this code into the CSS body {top: 0px !important; position: static !important; } .goog-te-banner-frame {display:none !important} but the drop down bar still has a spand the size a full sized website for some reason I pasted in the following code provided by google translate for the site: <div id="google_translate_element"></div><script> function googleTranslateElementInit() { new google.translate.TranslateElement({ pageLanguage: 'en', includedLanguages: 'zh-CN,zh-TW,en,de,ja,ko,th', layout: google.translate.TranslateElement.InlineLayout.SIMPLE }, 'google_translate_element'); } </script><script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script> Is there any code that can be added to restrict the size of this bar? again the translate option works outside of this. Thanks Dave Hello Everyone! I'm new to the forums but have a question with Google Translate I'm trying to add to my site. I believe the code for Google Translate is a Java Script and I'd like to put this on my website in the side column. The only thing I would like to modify is a <br> (break) between the Powered by and Google Translate. So I would like it to be center aligned like: Powered by Google Translate Right now it is stretching out the column because of the added space and frustrating me! Any idea how to do this? Here is the code: Code: <div id="google_translate_element"></div><script> function googleTranslateElementInit() { new google.translate.TranslateElement({ pageLanguage: 'en' }, 'google_translate_element'); } </script><script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script> My knowledge of javascript and coding in general is very very limited so any changes you make or where I should put the code, definitely let me know Thanks, Phil Hey I need some advice about Google translate, basically if you go to http://translate.google.com/#en|ja|Hello%20world and hover your mouse over the Japanese writing you will see it glow yellow ant allows you to click it to switch the text to something else to turn the string into the correct translation. What I want advice with is when I use the Google translate API am I able to obtain that list and output them onto my page. For example if a user writes in a textbox "Hello World" I want the API to return the list of possible translations for that string, something like this. Code: Language 1: en Language 2: ja String: Hello World ## Splits the string up by it's words -- Start Hello 1. こんにちは - Hi 2. ハロー - Halo 3. 挨拶 - Greeting 4. 投稿 - Posts World 1. 、世界 - World 2. 世界 - World 3. 世界の - World 4. 世界中 - Worldwide 5. の世界 - World ## Splits the string up by it's words -- End ## Uses each translated word to build a final list with all possible outcomes Hello World - (all possible outcomes) 1. こんにちは、世界 - Hello World 2. こんにちは世界 - Hello World 3. こんにちは世界の - Hello World 4. こんにちは世界中 - Hello world 5. こんにちはの世界 - Hello World 6. ハロー、世界 - Hello World 7. ハロー世界 - Hello World 8. ハロー世界の - Hello World 9. ハロー世界中 - Hello world 10. ハローの世界 - Hello World 11. 挨拶、世界 - Greetings, world 12. 挨拶世界 - Greetings the World 13. 挨拶世界の - Greetings World 14. 挨拶世界中 - Greetings Worldwide 15. 挨拶の世界 - Greetings World 16. 投稿、世界 - Post World 17. 投稿世界 - Post World 18. 投稿世界の - Post World 19. 投稿世界中 - Posts Worldwide 20. 投稿の世界 - Post World ## The final array that will be used for printing to the page. ## Only these have been chosen because the string equals the ## same but also the capital letters are the same as well. 1. こんにちは、世界 - Hello World 2. こんにちは世界 - Hello World 3. こんにちは世界の - Hello World 4. こんにちはの世界 - Hello World 5. ハロー、世界 - Hello World 6. ハロー世界 - Hello World 7. ハロー世界の - Hello World 8. ハローの世界 - Hello World How can I do this, with or without the use of Google's API???? Hello! I am trying to find a script that allows you to open multiple browser tabs and then close each of those tabs, either one by one or all at once. Does anyone know how to do this please? Thanks so much for your help. I want to have another go at Javascript. I have several books on the subject but I find that my eyesight is a major problem. Therefore I want to try an on-line solution, preferably free. I have Googled, but there are so many that I am almost dizzy with the choices. Perhaps someone could recommend one. Not too fussy visually. My knowledge is VERY basic. Frank Does anyone know how to make URL links that use Javascript still work when users have Javascript disabled on their browser? The only reason I'm using JS on a URL is because my link opens a PDF file, and I'm forcing it not to cache so users have the latest version. I tried the <script><noscript> tags, but I'm not sure if I'm using it correctly, as my URL completely disappears. Below is my HTML/Javascript code: <p class="download"> <script type="text/javascript">document.write("<span style=\"text-decoration: underline;\"><a href=\"javascript:void(0);\" onclick=\"window.open( 'http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf?nocache='+ Math.floor( Math.random()*11 ) );\" >The Child Magazines Media Kit</a></span> (PDF 1 MB) ");</script> <noscript><span style="text-decoration: underline;"><a href="http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf" >The Child Magazines Media Kit</a></span> (PDF 1 MB)</noscript> </p> Thanks for any help, Michael Hi Guys, I am new at JavaScript and start to do some tutorials.What I am trying to do here is prompting user to input a name and if the name was valid the page(document) will display with all objects like the button.But if user enter a wrong name then the button will be disabled! I create the following code but it did not work <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>New Web Project</title> <script language="JavaScript" type=""> function changeColor(){ document.bgColor = "Gray"; } </script> </head> <body> <script language="JavaScript" type="text/javascript"> var person = ""; person = prompt('What is Your Name:'); if (person == "Foo") { document.write("<h1 />Welcome " + person); document.bgColor = "Yellow"; } else { document.write("<h1 />Access Denied!!!!"); document.bgColor = "Red"; document.getElementById("gree").disabled = true; } </script> <div> <p/><input id="gree" type="button" value="Gray " onClick="changeColor();"> </div> </body> </html> as you can see I used the: document.getElementById("gree").disabled = true; but it did not work , could you please give an idea how I can solve this problem? Thanks Hi, I have the following code snippet: test.html ====== <script language="javascript" type="text/javascript"> var testVariable = "test"; </script> <script language="javascript" type="text/javascript" src="test.js"> </script> test.js ===== var testVariable = window.top.testVariable; In firefox, I'm able to access testvariable defined within test.html in test.js. But in chrome, test.js couldnot get the window.top.testVariable field defined in test.html. Can any one please let me know how i can make it work in chrome?. Am i missing something here?. I want to insert this js snippet Code: function addText(smiley) { document.getElementById('message').value += " " + smiley + " "; document.getElementById('message').focus(); return false; } to a loaded iframe with name&id chtifrm. I can access it & change embed something in its html via using something like: Code: $(parent.chtifrm.document.body).append('<div id=\"smly\" style=\"cursor:pointer;float:left;top:200px;display:none;position:absolute;\"><\/div>'); .... Code: parent.chtifrm.document.getElementById('chatbox_option_disco').style.display == 'none' but how do I insert js in the head of loaded iframe? Hi Guys I am trying to modify the functionality of my page. I want to be able to activate this piece of code using another javascript function. This is the code I want to activate: Code: <script type="text/javascript"><!-- $('#button-cart').bind('click', function() { $.ajax({ url: 'index.php?route=checkout/cart/update', type: 'post', data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea, .date_data input[type=\'text\']'), dataType: 'json', success: function(json) { $('.success, .warning, .attention, information, .error').remove(); if (json['error']) { if (json['error']['warning']) { $('#notification').html('<div class="warning" style="display: none;">' + json['error']['warning'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>'); $('.warning').fadeIn('slow'); } for (i in json['error']) { $('#option-' + i).after('<span class="error">' + json['error'][i] + '</span>'); } } if (json['success']) { $('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>'); $('.success').fadeIn('slow'); $('#cart_total').html(json['total']); $('html, body').animate({ scrollTop: 0 }, 'slow'); } } }); }); //--></script> And this is how I want the format of the function to be: function testsession() { if there is a session called 'hiredate' { activate the script above } else { var el = document.getElementById("product_data"); } } I just dont know how to write this in javascript Could you help me if possible please I got an index.php Code: <html> <form action="bacakomik.php" method='post'> <select name="kodekomik"> <option value='../komik1/|23'>Judul Komik1</option> <option value="../komik2/|20">Judul Komik2</option> <option value="../komik3/|10">Juduk Komik3</option> <option value="../komik4/|20">Judul Komik4</option> </select> <input type="submit" /> </form> <?php echo ('<select>'); echo ('<option value= "'.$i.'">'.'Page '.$i.'</option>'); echo ('</select>'); ?> </html> As you can see, each of the option brings specific value "../komik1/|23" komik1 is a directory | is a delimiter 23 is the pages in one chapter and can be considered also as how many images are there on a specific directory This is my bacakomik.php Code: <?php $dirkomik = $_POST['kodekomik']; $exploded = explode("|", $dirkomik); echo ($exploded[0]); //picture directory echo ("<br>"); echo ($exploded[1]); //total page in the comic $pagecount = (int)$exploded[1]; //Take last posted value, process it right away echo ('<FORM name="guideform"> '); echo ('<select name="guidelinks">'); $i=1; do { echo ('<option value= "'.$i.'">'.'Page '.$i.'</option>'); $i= $i+1; }while($i <= $pagecount); //Printing option and select echo ("</select>"); ?> <input type="button" name="go" value="Go!" onClick="document.getElementById('im').src=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value+'.png';"> </FORM> <img src="img0.jpg" id="im"> With the current code on bacakomik.php, I only can change the img src of id "im" in the same directory only. What I want is that the Javascript could "add" the "$exploded[0]" variable so that the picture can be loaded from different directory. Anyone can do this? I believe that the fix should be somewhere on input tag inside OnClick, or do you know where? Anyway, I found this on the net http://p2p.wrox.com/php-faqs/11606-q...avascript.html Please help me to those who can... Hey, I've got to make the values of some textboxes change the co-ordinates of my sprite on a canvas and havent a clue on how to do it, Here is my form with the two textboxes and submit button: <form> x: <input type="text" name="x" /><br /> y: <input type="text" name:"y" /><br /> <input type="submit" value="Submit"/><br /> </form> And i need it so that they change the values of these: //this shows where my sprite will start on the canvas var block_x; var block_y; searched the internet for hours and cant really find anything i understand or works. any help is much appreciated All -- I have a JavaScript config file called gameSetting.js which contains a bunch of variables which configures a particular game. I also have a shared JavaScript library which uses the variables in gameSetting.js, which I include like so: <script type="text/javascript" src="gameSetting.js" ></script> <script type="text/javascript" src="gameLibrary.js" ></script> In gameSetting.js I have: $(document).ready(function() { // call some functions / classes in gameLibrary.js } in Firefox, Safari, and Chrome, this works fine. However, in IE, when it's parsing gameSetting.js, it complains that the functions that live in gameLibrary.js aren't defined. When it gets to parsing gameLibrary.js, the variables in gameSetting.js are reported as not being defined. I've tried dynamically bootstrapping the gameLibrary file using this function in document.ready for dynamic load... $.getScript("gameLibrary.js"); However, the same problem still happens in IE, where when it parses the files individually it's not taking into context the file/variables that came before, so it's not an out of load order problem. My options a 1) collapsing all the functions in gameLibrary.js and variables in gameSetting.js into one file. However, this is not practical because this is dealing with literally hundreds of games, and having a gameLibrary.js in ONE location for ONE update is what makes most logical sense. 2) figure out a way to get this to work where variables in file1 are accessible to file2 in IE (as it seems they are in other browsers). jQuery seems to be able to have multiple plugins that all refer to the based jQuery-1.3.2.js, so I know there is a way to get this to work. Help appreciated. Nero I wrote a log function that took note of various function calls. Thinking that functions are first class objects, and objects have properties, I made the name of each logged function a property of that function, e.g., brightenInnerPara.name = "brightenInnerPara"; Every browser I tried (Firefox, MSIE, Opera, Chrome, Safari) accepted the assignment, no problem. In Firefox and MSIE, the result was what I wanted: brightenInnerPara.name == "brightenInnerPara" But in the others, the result was: brightenInnerPara.name == null Question 1. Which Javascript is correct here? I favor Firefox and MSIE, not merely because they were willing to give me what I wanted, but also because it makes no sense to accept an assignment statement without throwing an error and then give it a null semantics, like Chrome, Opera, and Safari did. I found a workaround, using assignments like this: brightenInnerPara.prototype.name = "brightenInnerPara"; To my surprise, that worked in every browser. But I don't know why. It seems that such assignments are enough to cause each function to have its own distinct prototype. Question 2. Just how inefficient is my workaround, and why does it work? I'm not sure if this is a javascript error or what. The webdeveloper toolbar says I have an error on my site which reads: Error: Permission denied for <http://googleads.g.doubleclick.net> to call method Location.toString on <http://www.*******************>. and also a few more saying undefined _popupControl I can't see what the problem is. The google ads are not showing on my site and I'm guessing these errors are the cause of that. Any help with this is much appreciated. Site: durkmusicbeats . com Thanks. This is a basic question, in the code below if I inputed 2 how can I echo the word hello? Code: <HTML> <HEAD> <TITLE>Test Input</TITLE> <SCRIPT LANGUAGE="JavaScript"> function testResults (form) { var TestVar = form.inputbox.value; if(TestVar!=2) { document.write("please enter 2"); } } </SCRIPT> </HEAD> <BODY> <FORM NAME="myform" ACTION="val4.php" METHOD="post">Enter something in the box: <BR> <INPUT TYPE="text" NAME="inputbox" VALUE=""><P> <INPUT TYPE="submit" NAME="button" Value="Click" onClick="testResults(this.form)"> </FORM> <?php if (isset($_POST['button'])) { echo "hello you inputed the right value"; } ?> </BODY> </HTML> So i have this: Code: #wrap { background-color:#FFFFFF;filter:alpha(opacity=80);opacity:.6; } And with javascript I want to basically, make turn the opacity up, so i tried this: Code: function mouseOver() { document.getElementById('wrap').style.background-color = "#FFFFFF;filter:alpha(opacity=80);opacity:.9;" } Though it's not working, can anyone help me? |