JavaScript - Spliting A String?
Hi, I'm coding a program to help people at my office to update the database, and the idea is to copy the content of an excel file and generate an sql from that, but I'm having a bit of trouble splitting the info into different tables:
When copying everything the empty cells are read as tabulated, so I made a for that searches for more than one tabulator in a row (or find a \n and a following tabulator character) to split the info into several strings and format the info into a sql table, but I'm stuck he Code: var X=document.getElementById('opc'); var z=X.value.length; for(i=0;i<z;i++){ if(X.charAt(i)==' '&& X.chaAt(i+1)==' '){ char=X.value.substring(0,i-1); break; } } I tried with X.value(i) but I get the same error 'X.charAt is not a function', can someone tell me what am I doing wrong? Thanks. Similar TutorialsHey 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 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")%>"} } 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? 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)); Hi guys im new here i have a project about searching string im am going to use javascript the program should look like this. Enter first word: abcd Search in first Word: ab then pop up ab found then if i type like sdg then pop up sdg not found something like this plss how can i do that When comparing an empty string "" to another string like "1232", javascript is returning true. Why is that?
I am using javascript to search for the '*' character in a string (ie. 'username*:') but using search('\*') does not work. How do I search for it since the search function takes a regexp argument and * messes that up?
Hi everyone... I'd written a code to split a string like below: Input string: a=>aa|b=>b||b|c=>cc and the output: a=>aa b=>b||b c=>cc I use .Match() to do that as below: var matches = "a=>aa|b=>b||b|c=>cc".match(/(?:[^|]|\|\|)+/g) I want to use tha .Split() to split the above string. please help me... Hi I have a given url and want to back up a level. So for example if start with: url = "test/level1/level2/level3/" I would like to it remove the "level3/" to become url="test/level1/level2/" Hey guys. I'm trying to display a grid of data basically, but inside a table and with appropriate closing and beginning of td and tr tags. I'm having a very weird problem. Here is my code: Code: tasks = document.getElementById('tasks'); var i = 0; tasks.innerHTML = <tablebgcolor=silver>"; while (i < 3) { tasks.innerHTML = tasks.innerHTML + "<tr><td>"; tasks.innerHTML = tasks.innerHTML + text[i][0]; tasks.innerHTML = tasks.innerHTML + "</td><td>"; tasks.innerHTML = tasks.innerHTML + text[i][1]; tasks.innerHTML = tasks.innerHTML + "</td><td>"; tasks.innerHTML = tasks.innerHTML + text[i][2]; tasks.innerHTML = tasks.innerHTML + "</td></tr>"; i++; } tasks.innerHTML = tasks.innerHTML + "</table>"; The html just doesn't work when it's in a string. I have to put each "<tr><td>", "</td><td>", </td></tr>", <table bgcolor=silver>", etc. into it's own variable and do it that way. That doesn't seem like it should be happening and I don't think it would be good to do it that way in the long run. Can someone tell me what I'm doing wrong? Hi, I have a string stored in a variable var = "4.25 houses". I would like to only extract the currency value, ie "4.25" from this. Is this possible? Also I would like to divide and multiply the new variable I get... does this number need to be converted or something? Thanks in advance! Help, I can't figure out why this doesn't work. Thanks.. [CODE] 1 //==UserScript== 2 // @name Add youcalc highrise tab 3 // @namespace http://www.youcalc.com/ 4 // @include http://*.highrisehq.com/* 5 // @include https://*.highrisehq.com/* 6 // @exclude http://www.highrisehq.com/* 7 // @exclude http://forum.highrisehq.com/* 8 // @exclude https://www.highrisehq.com/* 9 // ==/UserScript== 10 11 //change to your needs 12 13 appurl1 = "http://www.youcalc.com/pubapps/1232017802730/"; 14 tabtitle1 = "Deals and forecast"; 15 appwidth1 = "830px"; 16 appheight1 = "690px"; 17 18 appurl2 = "http://www.youcalc.com/pubapps/1226931095311/"; 19 tabtitle2 = "Deals Activity Report"; 20 appwidth2 = "830px"; 21 appheight2 = "690px"; 22 23 appurl3 = "http://www.youcalc.com/pubapps/1229432659119/"; 24 tabtitle3 = "Contacts By Tag"; 25 appwidth3 = "830px"; 26 appheight3 = "690px"; 27 28 //from here, change at own risk 29 tabs = document.getElementById('Tabs'); 30 tabshtml = tabs.innerHTML; 31 32 //new tab html and JS 33 youcalcapp1 = '<iframe src=' + appurl1 + ' width=' + appwidth1 + ' height=' + appheight1 + ' style=border:none; />'; 34 youcalcapp2 = '<iframe src=' + appurl2 + ' width=' + appwidth2 + ' height=' + appheight2 + ' style=border:none; />'; 35 youcalcapp3 = '<iframe src=' + appurl3 + ' width=' + appwidth3 + ' height=' + appheight3 + ' style=border:none; />'; 36 37 putyoucalc1 = "inner_body = document.getElementById('screen_body');inner_body.innerHTML = '"+ youcalcapp1 + "';yct1 = document.getElementById('youcalctab1');yct1.className='current';yct2 = document.getElementById('youcalctab2');yct2.className='';";yct3 = document.getElementById('youcalctab3');yct3.className='';"; =========================================================^ SyntaxError: unterminated string literal 38 putyoucalc2 = "inner_body = document.getElementById('screen_body');inner_body.innerHTML = '"+ youcalcapp2 + "';yct2 = document.getElementById('youcalctab2');yct2.className='current';yct3 = document.getElementById('youcalctab3');yct3.className='';";yct1 = document.getElementById('youcalctab1');yct1.className='';"; 39 putyoucalc3 = "inner_body = document.getElementById('screen_body');inner_body.innerHTML = '"+ youcalcapp3 + "';yct3 = document.getElementById('youcalctab3');yct3.className='current';yct2 = document.getElementById('youcalctab2');yct2.className='';";yct1 = document.getElementById('youcalctab1');yct1.className='';"; 40 41 //find last tab, and put youcalc tab after 42 lasttab = 'Tags</a></li>'; 43 youcalctabs = '<li class="with_space" ><a class="" id="youcalctab1" onclick="' + putyoucalc1 + '" href="#">' + tabtitle1 + '</a></li><li class="with_space" ><a class="" id="youcalctab2" onclick="' + putyoucalc2 + '" href="#">' + tabtitle2 + '</a></li>';<li class="with_space" ><a class="" id="youcalctab3" onclick="' + putyoucalc3 + '" href="#">' + tabtitle3 + '</a></li>'; 44 tabshtml = tabshtml.replace(lasttab,lasttab+youcalctabs); 45 tabs.innerHTML = tabshtml; 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? Hi, I'm working on refining my search function. At the moment it works fine like this: Code: function searchLocations() { var found = false; var input = document.getElementById('autocomplete').value; for (var j = 0; j < gmarkers.length; j++) { if (gmarkers[j].myname.toLowerCase() == input.toLowerCase()) { found = true; gmarkers[j].show(); myclick(j); } } if ( ! found ) alert("No matches found. Please check your spelling or refine your search."); } but you have to get the input exactly the same as it is in the array for it to work (as it should, being that that's the way it's written). I wanted to split it so that for example Black Cat Hotel would pop if the user entered Black OR Cat OR Hotel (or any combination of the above). So I thought that this might work: Code: function searchLocations() { var found = false; var input = document.getElementById('autocomplete').value; for (var j = 0; j < gmarkers.length; j++) { var s = gmarkers[j].myname.toLowerCase().split(" "); if ( s == input.toLowerCase()) { found = true; gmarkers[j].show(); myclick(j); } } if ( ! found ) alert("No matches found. Please check your spelling or refine your search."); } but obviously not. Is there some better way to do this? How to handle String in Javascript
Hello, I need your help. How could I write a functional if statement such that it would check against a series of various word strings seperated by commas ie. function check(y) { //y = "FOR INPUT" var string_to_check = FOR INPUT, FOR ACTION, FOR APPROVAL if (y isin string_to_check) { return 1 } } Thanks for everyones help. J Hello, I need your help. Let's say for example if I have the following file number: 2011-1234567 and if the value of the variable is already the same (ie. var fileNo = 2011-1234567) how can I go about automatically adding a number at the end? ex.1.) var fileNo = "2011-1234567" if (fileNo already exists) { fileNo = 2011-1234567-2 } ex.2.) var fileNo = "2011-1234567-2" if (fileNo already exists) { fileNo = 2011-1234567-3 } ect. Much thanks and appreciation for all your help. Jay |