JavaScript - Getting Regxp Data From The Get Method In Jquery
hey guys im using greasmonkey with jquery and i want to find the remaining time on a page then display it in my infomation bar in game but what im having trouble with is the regxp trying to get the text then get the 1,2 or 3 didgit number between the text here is my current function which gets the numbers on the page but returns a HUGE number because its returning every number
Code: function getFallen() { hellGate = ""; $.get('http://kong.playmage.com/dream/fallen?board', function(data) { temp = data; if(temp.search("Time until revival:") != -1 || temp.search("minutes") != -1) { numb = temp.match(/\d/g);//format of text needed "Time until Revial (number 1,2 or 3 didgits long) minutes" numb = numb.join("");//with the current match i have it returns huge number //debugScript("Found the number :" + numb, "debug"); //el2 = $inc1("test"); function outside this function just for finding classes/ids //if (el2) el2.textContent = numb; // for setting the content of the id class above not needed in this function but just for debug purposes } }); } now oviously this get function WILL NOT work for you because you will need to log in so if you just store the following html into the temp var then it will function the same Code: <input type="hidden" id="cfix" value=""/> <center><span style="padding-top: 4px; display: inline-block; font-size: 16px; color: #00ddbb; font-family: lucida grande, verdana, arial;">Fallen Defenders</span> <br /> <table style="width: 100%;" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <div style="text-align: center;">Last Fallen</div> <div class="trainlbox" style="height: 346px; overflow-x: hidden; margin: 5px 4px 5px 12px; display: inline-block;"> <table style="width: 332px;" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr style="vertical-align: middle; background-color: rgb(0, 36, 36);"> <td class="healheadertd" style="width: 50px;"> Rank</td> <td class="healheadertd" style="width: 120px;">Player</td> <td class="healheadertd" style="text-align: center;">Damage </td> </tr> <tr style="vertical-align: middle;"> <td> 1</td> <td> <a href="#" onclick="showDiv('/dream/profile?id=nf110743'); return false;">Authority[aik]</a> </td> <td style="text-align: center;">1,479,141,013 </td> </tr> <tr style="vertical-align: middle;"> <td> 2</td> <td> <a href="#" onclick="showDiv('/dream/profile?id=nf483977'); return false;">Ultima[HOT]</a> </td> <td style="text-align: center;">603,063,918 </td> </tr> <tr style="vertical-align: middle;"> <td> 3</td> <td> <a href="#" onclick="showDiv('/dream/profile?id=nf402815'); return false;">wozza[AGA]</a> </td> <td style="text-align: center;">287,130,506 </td> </tr> <tr style="vertical-align: middle;"> <td> 4</td> <td> <a href="#" onclick="showDiv('/dream/profile?id=nf404165'); return false;">larry1977[AGA]</a> </td> <td style="text-align: center;">277,033,578 </td> </tr> <tr style="vertical-align: middle;"> <td> 5</td> <td> <a href="#" onclick="showDiv('/dream/profile?id=nf455510'); return false;">Ehanida[ToF]</a> </td> <td style="text-align: center;">276,799,331 </td> </tr> <tr style="vertical-align: middle;"> <td> 6</td> <td> <a href="#" onclick="showDiv('/dream/profile?id=nf173542'); return false;">dudemanly[DNA]</a> </td> <td style="text-align: center;">191,656,885 </td> </tr> <tr style="vertical-align: middle;"> <td> 7</td> <td> <a href="#" onclick="showDiv('/dream/profile?id=nf191162'); return false;">krashkill0069[G4B]</a> </td> <td style="text-align: center;">47,831,724 </td> </tr> <tr style="vertical-align: middle;"> <td> 8</td> <td> <a href="#" onclick="showDiv('/dream/profile?id=nf486185'); return false;">ben_avatar[HOT]</a> </td> <td style="text-align: center;">33,264,175 </td> </tr> <tr style="vertical-align: middle;"> <td> 9</td> <td> <a href="#" onclick="showDiv('/dream/profile?id=nf312560'); return false;">Niv[PWN]</a> </td> <td style="text-align: center;">31,520,972 </td> </tr> <tr style="vertical-align: middle;"> <td> 10</td> <td> <a href="#" onclick="showDiv('/dream/profile?id=nf528295'); return false;">leandroaod[DJE]</a> </td> <td style="text-align: center;">26,510,757 </td> </tr> <tr style="vertical-align: middle;"> <td> 11</td> <td> <a href="#" onclick="showDiv('/dream/profile?id=nf187015'); return false;">Graveyard[PWN]</a> </td> <td style="text-align: center;">10,379,144 </td> </tr> <tr style="vertical-align: middle;"> <td> 12</td> <td> <a href="#" onclick="showDiv('/dream/profile?id=nf25358'); return false;">Maynard[PWN]</a> </td> <td style="text-align: center;">7,116,618 </td> </tr> <tr style="vertical-align: middle;"> <td> 13</td> <td> <a href="#" onclick="showDiv('/dream/profile?id=nf229143'); return false;">Barry McCociner[XXX]</a> </td> <td style="text-align: center;">6,123,612 </td> </tr> <tr style="vertical-align: middle;"> <td> 14</td> <td> <a href="#" onclick="showDiv('/dream/profile?id=nf79006'); return false;">DumMetlHed[PWN]</a> </td> <td style="text-align: center;">4,736,449 </td> </tr> </tbody> </table> </div> </td> <td> <div style="text-align: center;">Current Fallen </div> <div class="trainlbox" style="height: 346px; overflow-x: hidden; margin: 5px 8px; display: inline-block;"> <table style="width: 332px;" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr style="vertical-align: middle; background-color: rgb(0, 36, 36);"> <td class="healheadertd" style="width: 50px;"> Rank</td> <td class="healheadertd" style="width: 120px;">Player</td> <td class="healheadertd" style="text-align: center;">Damage </td> </tr> <tr><td colspan="3" style="text-align: center;"> <br/> <br/> <br/> <br/> Time until revival: 147 minutes </td></tr> </tbody> </table> </div> </td> </tr></tbody> </table> <div style="padding-top: 10px;"><span class="btn100" onclick="closeFloat();">Close</span></div> </center> would it be possible to only strip the following text Time until Revial (number 1,2 or 3 didgits long) minutes and then once it has found that match remove anything that isnt a number Similar TutorialsHi, I'm a newbie to the forum and jquery and have been trying to use it for a slick form wizard i found here. http://thecodemine.org/ It's almost complete but IE keeps giving me an error I've tried everything to fix with no luck. I'm using jquery-1.4.2.min.js and the error it's giving me is Unexpected call to method or property access. line 103 character 460 The code it highlights is: Code: {this.nodeType===1&&this.appendChild(a)})}, at the end of this line. Complete line is: Code: wrapInner:function(a){if(c.isFunction(a))return this.each(function(b){c(this).wrapInner(a.call(this,b))});return this.each(function(){var b=c(this),d=b.contents();d.length?d.wrapAll(a):b.append(a)})},wrap:function(a){return this.each(function(){c(this).wrapAll(a)})},unwrap:function(){return this.parent().each(function(){c.nodeName(this,"body")||c(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.appendChild(a)})}, Any help would be greatly appreciated. Thanks! FYI: Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) Timestamp: Tue, 15 Nov 2011 16:45:53 UTC Message: Unexpected call to method or property access. Line: 103 Char: 460 Code: 0 URI: http://custsatdev/contact/jqueryform...y-1.4.2.min.js Hey guys, I have the following regxp .match() Code: debugtest = debugtest.match(/(/**/ jordan30001[CD])/)[1]; what i want to do with this regxp is with the /**/ and what i want to do is make it match a 1 didgit number or a 2 didgit number for example 10 jordan30001[CD] or 1 jordan30001[CD] how would i acomplish this i know that i could change /**/ to \d\d but that would only find 2 numbers and not 1 if theres only 1 ts = equ.replace(new RegExp('[x\.\-\+\w\d\*\/\^\)\(%]+'),"") is not working. it is supposed to replace x,1,2,3,4,5,6,7,8,9,0,*,^,/,.,-,+,% and (whitespace) with nothing ('') I am going through the example at the bottom of this page: http://api.jquery.com/jQuery.getJSON/ I am using the following code: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <script src="http://code.jquery.com/jquery-1.4.4.js"></script> </head> <body> <script> var id=$("#id").attr("value"); $.getJSON("json.php",{id:id},dates); function dates(datos) { $("#list").html("Town:"+datos[1].rsTown+"<br>"+"County:"+datos[1].rsCounty); } </script> <div id="id"></div> <div id="list"></div> </body> </html> and I'm trying to pull my JSON data from my PHP page: http://www.mypubspace.com/dashtest/json.php the JQuery seems to be doing something but nothing is being output to my screen?! project page http://www.mypubspace.com/dashtest/json.html Please help?! You've probably seen this many times with two dynamic linking select boxes that deals in form or another deal with countries and then cities for the second one or something similar well I have another question about that. I've looked at a few others and well their coding is so different then mine that I don't want to use code for my own project that I don't understand in case I need to reuse it for some other reason down the road. The user selects a country and with the users selection it passes the countryid as a variable through jquery's ajax fuction as a post parameter to a php process page in which it goes to a table and matches the country id with the db field called country_id in the arenas table. With all the records that matches that countryid it selects the arena name and city that the arena is in and displays it as an option tag now I'm trying to figure out with muliple entries how can I pass the results back to the form page and insert it into the arenas dropdown box. Following is my coding separated out for you. I only included the necessary parts. All help would be greatly appreciated. form page Code: $('#countryid').change(function() { var countryid = $("select#countryid").val(); var dataString = 'countryid='+ countryid; $.ajax({ type: "POST", url: "processes/booking.php", data: dataString, success: function() { } }); }); <div class="field required"> <label for="countryid">Country</label> <select class="dropdown" name="countryid" id="countryid" title="Country"> <option value="0">- Select -</option> <?php $query = 'SELECT id, countryname FROM countries'; $result = mysqli_query ( $dbc, $query ); // Run The Query while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { print "<option value=\"".$row['id']."\">".$row['countryname']."</option>\r"; } ?> </select> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <div class="field required"> <label for="arena">Arenas</label> <select class="dropdown" name="arenas" id="arenas" title="Arenas"> </select> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> php process page PHP Code: $countryid = (int)$_GET['countryid']; $query = "SELECT * FROM `arenas` WHERE `country_id` = '$countryid'"; $result = mysqli_query ($dbc, $query); while ($row = mysqli_fetch_array($dbc, $result)) { echo '<option value="'.$row['arena'].'">'.$row['arena'].' - '.$row['city'].'</option>\n'; } Why is the callwhy is the slice method only a method of an Array instance? The reason why I ask is because if you want to use it for the arguments property of function object, or a string, or an object, or a number instance, you are forced to use Array.prototype.slice.call(). And by doing that, you can pass in any type of object instance (Array, Number, String, Object) into it. So why not just default it as a method of all object instances built into the language? In other words, instead of doing this: Code: function Core(){ var obj = {a : 'a', b : 'b'}; var num = 1; var string = 'aff'; console.log(typeof arguments);//Object console.log(arguments instanceof Array);//false var args1 = Array.prototype.slice.call(arguments); console.log(args1); var args2 = Array.prototype.slice.call(obj); console.log(args2); var args3 = Array.prototype.slice.call(num); console.log(args3); var args4 = Array.prototype.slice.call(string); console.log(args4); Core('dom','event','ajax'); Why not just be able to do this: Code: function Core(){ var obj = {a : 'a', b : 'b'}; var num = 1; var string = 'aff'; var args = arguments.slice(0); var args2 = obj.slice(0); var args3 = num.slice(0); var args4 = string.slice(0); //right now none of the above would work but it's more convenient than using the call alternative. } Core('dom','event','ajax'); Why did the designers of the javascript scripting language make this decision? Thanks for response. So, i have this code which retrieves php files for me using jquery and id love to get it working with Jquery history plugin. I tried modifying the code i got from the ajax demo to work for me, but i just couldnt do it as i do not know any javascript really.. ( actually what i tried was simply to change "#ajax-links a" to "#menu li a" and .html to .php ..but nothing.. :rolleyes: Id be very gratefull if someone would help me out with this one. All related code can be found bellow (the ones that should be needed anyways): This is the code that retrieves php files inside "#content" when item from "#menu li a" with the specified id is clicked Code: $(document).ready(function(){ //References var change = $("#menu li a"); var loading = $("#loading"); var content = $("#content"); //Manage click events change.click(function(){ //show the loading bar showLoading(); //load selected section if(this.id == "home") { change.load(this.className='current-page'); content.slideUp(); content.load("pages/index.php", hideLoading); content.slideDown(); } else if(this.id == "secondpage") { change.load(this.className='current-page'); content.slideUp(); content.load("pages/secondpage.php", hideLoading); content.slideDown(); } else { //hide loading bar if there is no selected section hideLoading(); } }); //show loading bar function showLoading(){ loading .css({visibility:"visible"}) .css({opacity:"1"}) .css({display:"block"}) ; } //hide loading bar function hideLoading(){ loading.fadeTo(1000, 0); }; }); Heres the structure of the menu/content Code: <ul id="menu"> <li><a id="home" class="normal" href="#Home"></a></li> <li><a id="secondpage" class="normal" href="#Secondpage"></a></li> </ul> <div id="content"> <ul id="sec-menu"> <li><a id="link1" class="normal" href="#">Link1</a></li> <li><a id="link2" class="normal" href="#">Link2</a></li> </ul> </div> Heres the code that jquery history plugin uses in demo for ajax Code: jQuery(document).ready(function($) { function load(num) { $('#content').load(num +".html"); } $.history.init(function(url) { load(url == "" ? "1" : url); }); $('#ajax-links a').live('click', function(e) { var url = $(this).attr('href'); url = url.replace(/^.*#/, ''); $.history.load(url); return false; }); }); hi, i have a jquery problem... this script is not working with jquery-1.4.2.min, but it works with jquery-1.2.6.min.js, can anyone help me???the script is the above: (it is not working the tab actions, the slideout works...) http://www.benjaminsterling.com/wp-c...es/sidetab.htm the javascript code is the above: PHP Code: var jqsideTabs; var tabs, h = 50, r = 0,ra = 0; $(document) .ready(function(){ jqsideTabs = $('#sideTabs').addClass('closed'); tabs = jqsideTabs .find('.tab h3') .clone() .appendTo(jqsideTabs) .each(function(i){ var that = $(this), cls = '',ow,newThis, newEl; if( i == 0 ) cls = ' active'; newEl = $('<a href="#" class="tabLinks'+cls+'">' + that.text() + '</a>'); that.replaceWith(newEl); ow = newEl.outerWidth(); if( i == 0 ) ra = ow; else r = ow; h = newEl.css({'top':h , 'right': -ow }).height() + h; newThis = newEl.get(0); newThis.jq = newEl; newThis.i = i; newEl.click(function(){ var el = this.jq; if( jqsideTabs.hasClass( 'closed' ) ){ jqsideTabs.removeClass('closed'); } else if( !jqsideTabs.hasClass( 'closed' ) && el.hasClass('active') ){ jqsideTabs.addClass('closed'); } el .siblings() .removeClass('active') .css({'right': -r }) .end() .addClass('active') .css({'right': -ra }); tabs.eq( this.i ).show().siblings('.tab').hide(); return false; }); }) .end() .parent() .eq(0) .addClass('active') .end() .filter(':not(:eq(0))') .hide() .end(); jqsideTabs.bind("mouseleave",function(){ jqsideTabs .animate({left:-310}, 'fast', function(){ jqsideTabs.addClass('closed').removeAttr('style'); }); }); }); and the html file is: [HTML] <div id="sideTabs"> <div class="tab"> <h3>Tab 1</h3> <div class="gut"> <p>Some text</p> </div> </div> <div class="tab"> <h3>Tab 2</h3> <div class="gut"> <ul> <li>link</li> </ul> </div> </div> <div class="tab"> <h3>Tab 3</h3> <div class="gut"> <ul> <li>link</li> </ul> </div> </div> </div> [/HTML] the problem is that the tab button works, but the content doesnt change...in all of tabs showing the same text(showing all tbas content).... can anyone help...please..... i keep getting the error GET http://code.jquery.com/jquery.min.map net::ERR_TOO_MANY_REDIRECTS & Failed to load resource: net::ERR_TOO_MANY_REDIRECTS when i load my page...and the havascript doesn't work properly on ym page...how do i resolve this. thanx in advance var s="attr" var i=$(s) // jQuery(elem).attr(attr,eval("elm"+attr)); jQuery(elem).$(s)(attr,eval("elm"+attr));//i tried this. how to assign a variable name in the above code(in place of s) so that i need to add an attribute to the element "elem". So I'm new around here, and to web dev in general, but I've got a (hopefully) short question. I am trying to call a function (nextMonth()) every second from the time that the cycle method gets called, until it is called again. As of now I am trying to use setInterval, (and I previously tried with setTimeout and using a callback argument but maybe I wasn't doing that properly). The problem is that after running the cycle() method for 5 or 6 seconds, the entire browser freezes up and you have to kill it and restart it. Here is my code as of now: Code: function cycle() { if(CYCLEINT != null) //STOP THE CYCLE LOOP { window.clearInterval(CYCLEINT); CYCLEINT = null; document.getElementById("cycle").innerHTML = "Cycle Months"; } else //LOOP IS NOT RUNNING, INITIATE AND CONTINUE INTERVAL. { CYCLEINT = self.setInterval("nextMonth()", 1000); document.getElementById("cycle").innerHTML = "Pause"; } } function prevMonth() { var dVal = $( ".slider" ).slider( "option", "value"); if(dVal > 1) { dVal--; $( ".slider" ).slider( "option", "value", dVal ); refresh(); } } function nextMonth() { var dVal = $( ".slider" ).slider( "option", "value"); if(dVal < dateMax) { dVal++; $( ".slider" ).slider( "option", "value", dVal ); refresh(); } if(CYCLEINT != null && dVal >= dateMax) { cycle(); } } Im working on learning JavaScript with the help of a text book, below is the current script I am working on regarding handling forms. This script should populate the "Days" field depending on the Month selected. I understand most of it except for the parseInt function. Could anyone help describe it to me? I understand it turns a String into a Value...hmm Code: window.onload = initForm; function initForm() { document.getElementById("months").selectedIndex = 0; document.getElementById("months").onchange = populateDays; } function populateDays() { var monthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31); var monthStr = this.options[this.selectedIndex].value; if (monthStr != "") { var theMonth = parseInt(monthStr); document.getElementById("days").options.length = 0; for(var i=0; i<monthDays[theMonth]; i++) { document.getElementById("days").options[i] = new Option(i+1); } } } Thank you! I am very interested in learning this and would love any help! I am trying to impliment Javascript code to replace the MS Tabular data control. How do I go about creating a Fields collection object that has a default method of Item(idx) ie. myrs.Fields.Item(4).name is the same as myrs.Fields(4).name Hi there I'm trying to figure out what the following syntax for split means in the following line of the code arrTest[0].split('/')[0] what does ('/')[0] means in split('/')[0]? please can anyone explain I am using javascript for adding and removing rows from table as per user require ment like if we press ADDROW button it adds extra row to table and if we pressREMOVEROW it delets the last row.. Now i want to access the data from textbox like this.. var crpt = document.getElementById("itrtr2").value; //no. of rows for(var k=1;k<=crpt;k++) { qtyc = document.getElementById("txtRowc3"+k).value; unit_pricec = document.getElementById("txtRowc5"+k).value; alert('QTYC:'+qtyc+' UPC:'+unit_pricec); cttl = qtyc * unit_pricec; document.getElementById("txtRowc6"+k).value = cttl.toFixed(2); csbttl = csbttl + cttl; } document.getElementById("subttlC").value=csbttl.toFixed(2); it shows the value of textRowc3i in qtyc in alert box but also givs error document.getElementById("txtRowc3"+k) is null.. I tried for this but problem is not solved please help... Thank You... I'm trying to write a method called printPowersOfN that accepts a base and an exponent as arguments and prints each power of the base from base0(1) up to that maximum power, inclusive. For example, I'm trying: printPowersOfN(4, 3); printPowersOfN(5, 6); printPowersOfN(-2, 8); which should give me: 1 4 16 64 1 5 25 125 625 3125 15625 1 -2 4 -8 16 32 64 -128 256 but I only get: 64 15625 256 Here's my code: Code: public class Powers { public static int printPowersOfN (int base, int exponent) { int answer = 1; for (int i=1; i <= exponent; i++) { answer*=base; } return answer; } public static void main(String[] args) { System.out.println(printPowersOfN(4, 3)); System.out.println(printPowersOfN(5, 6)); System.out.println(printPowersOfN(-2, 8)); } } What should I change so that it does all of the powers? When you use a form and submit it the URL bar changes to what the submitted values are. So can anyone explain how to use this?
I'm a newbie of JS and don't know if I have got the right terms in my question. I want to lowercase all the arrays: Code: <script> var txt = [ ["Cats","Dogs","Rabbits"], ["Fish","Bones","Carrots"] ] document.write(txt[0][1] + " love eating " + txt[1][1]); </script> I know I can do something like this: Code: document.write(txt[0][1].toLowerCase() + " love eating " + txt[1][1].toLowerCase()); // or var txt1 = txt[0][1] + " love eating " + txt[1][1]; document.write(txt1.toLowerCase()); But if I will loop through all the arrays and print them out, I am bothered with appending .toLowerCase(0 after each array one by one, so is there any way to bind that method at one go? I hope my question is understandable. Maybe I've used wrong terms of JS. Thank you. i want to write a code which would prompt the user for his first name and last name with space in between them.The full name must be entered in the same prompt box.Using the charCodeAt() method i wanna test the first character of the user's first name as well as last name.If the first character of first name is in lowercase then it should alert the user as "first name must start with uppercase".And if the first character of second name is in uppercase then it should alert the user as "second name must start with lowercase". ..plzzzz help me and give me some code for this..i m a beginner in javascript..
|