quagmire02 All American 44225 Posts user info edit post |
Quote : | "I don't understand what you mean" |
google "jquery limit characters" and you get results like these:
http://www.ajaxray.com/blog/2007/11/09/interactive-character-limit-for-textarea-using-jquery/ http://www.devcurry.com/2009/08/limit-number-of-characters-in-textarea.html
that demonstrate how to do this individually for each instance, but it isn't very dynamic (i feel like there's a lot of wasted code if you use it more than once)
Quote : | "He means he doesn't want to have to call the plugin for each instance he wants it used but rather have the plugin find all textareas on page load" |
exactly...i'm not adept enough with jquery to determine whether or not there's anything wrong with my method, but it sure does cut down on the amount of code i have to write since i use it in 20+ places
Quote : | "man why are you not just using a class instead of doing something you know is wrong" |
you mean use class="150" instead of maxlength="150"?
[Edited on March 3, 2010 at 10:21 AM. Reason : .]3/3/2010 10:17:50 AM |
FroshKiller All American 51911 Posts user info edit post |
bingo
or something more descriptive, even
like a class called "limited" plus a number
like "limited50words"
and you can parse out all classes beginning with "limited"
get the words or characters limit
i mean classes are your foundation here
even multiple classes
class="limited words" etc.
[Edited on March 3, 2010 at 10:24 AM. Reason : ook] 3/3/2010 10:21:32 AM |
quagmire02 All American 44225 Posts user info edit post |
^ because it validates anyway...i would think calling a class that doesn't exist is worse than using an attribute that doesn't exist when it doesn't throw any validation flags 3/3/2010 10:22:51 AM |
FroshKiller All American 51911 Posts user info edit post |
i don't think you understand the point of classes
they are the core of html4+ extensibility
a class is not an object (or element, if you like) that does or does not exist
it's just a way to classify and address elements
[Edited on March 3, 2010 at 10:26 AM. Reason : ...] 3/3/2010 10:23:57 AM |
Ernie All American 45943 Posts user info edit post |
This is what I was getting at 3/3/2010 10:31:42 AM |
quagmire02 All American 44225 Posts user info edit post |
that's a good point...i realize HTML 5 is a ways off, but since the textarea element will support the maxlength attribute (IIRC) then and it doesn't cause any validation problems now, not sure why i WOULDN'T do it this way...if it validates, what difference does it make?
you are also right in that i didn't (don't) think of classes that way...i'll think about it
in any case, this discussion doesn't contribute anything to my question...whether i waste more code parsing the text or continue to use my not-invalid markup, the jquery issue is still there 3/3/2010 10:39:46 AM |
FroshKiller All American 51911 Posts user info edit post |
well just consider this
even standards-compliant browsers don't consistently handle invalid attributes on elements that don't support them
so using classes instead will give you more predictable and controllable results in circumstances where the user agent for whatever reason doesn't render the document as you intended
e.g. the user has javascript turned off
and html5 is not going to make classes obsolete
anyway your issue will be easier to troubleshoot if you provide the actual content, your expected result, and the result you actually got
[Edited on March 3, 2010 at 10:44 AM. Reason : ...] 3/3/2010 10:43:44 AM |
Stein All American 19842 Posts user info edit post |
Quote : | "i'm sure it has something to do with my substr, but i can't figure out why it's going back to 20" |
The code is doing exactly what you're telling it to. Think about what values are getting put into your substring regardless of whether you have 50 words or 50 characters.
[Edited on March 3, 2010 at 10:51 AM. Reason : .]3/3/2010 10:45:57 AM |
robster All American 3545 Posts user info edit post |
Need some help, if anyone can take a look.
I am combining a few jquery plugins/widgits/whatever ....
http://eventscream.com/clients/calendar.php
When you unclick on "All Day?" at the right hand side, a div is unhidden, which has the start time and end time.
When you put your cursor in "start time" text field, a drop down/select box appears ... but it shows up at the top left of the webpage.
Its been doing this ever since I added the datepicker widget to the page, and I cant figure out what is causing this to happen.
Any help is appreciated. 3/5/2010 8:33:39 AM |
FroshKiller All American 51911 Posts user info edit post |
well i was all set to open firebug to inspect the element
but you have one of those gay fucking anti-right-click scripts
so no go
[Edited on March 5, 2010 at 8:52 AM. Reason : though it's probably a relative vs. absolute positioning issue] 3/5/2010 8:52:07 AM |
robster All American 3545 Posts user info edit post |
Ah ... sorry .. was playing with that crap, and didnt turn it off...
Its off now, in case you are willing to give it a second look. 3/5/2010 9:02:49 AM |
FroshKiller All American 51911 Posts user info edit post |
in timePicker.js
$tpDiv.appendTo('body').css({'top':elmOffset.top, 'left':elmOffset.left}).hide(); there's your booger
anyway can i ask why this isn't just a select element to begin with
[Edited on March 5, 2010 at 9:11 AM. Reason : in case i wasn't clear]3/5/2010 9:07:08 AM |
robster All American 3545 Posts user info edit post |
I guess because when looking for a time selector, this already did some of the basic stuff I wanted it to do ... just looks like junk in that its a select box.
I am looking at another option as well ... but havent decided if its adds any "ease of use" yet
http://www.jnathanson.com/index.cfm?page=jquery/clockpick/ClockPick
update: Fixed by unhiding that <p> element from the get-go ... I guess since it was in a display:none element at run time, it just wrote the new div and appended it to the top left of the page instead of the top left of where the element appeared ...
Know of a quick way to workaround that dynamically in the script?
[Edited on March 5, 2010 at 9:21 AM. Reason : update] 3/5/2010 9:12:41 AM |
FroshKiller All American 51911 Posts user info edit post |
You basically just need to change the timePicker script a bit so that it appends that $tpDiv to the element that called the function rather than to the body element. You will probably need to tweak the offsets, but there it is. 3/5/2010 9:20:36 AM |
qntmfred retired 40726 Posts user info edit post |
bump 8/17/2011 3:08:11 PM |
quagmire02 All American 44225 Posts user info edit post |
^ thanks!
when i list images within a specific div, i want to append the image source to refer to the smaller version...for example: <div class="goobers"> <img src="/images/mikeandike.jpg" /> </div> <div class="goobers"> <img src="/images/redhots.gif" /> </div> turns into<div class="goobers"> <img src="/images/mikeandike_small.jpg" /> </div> <div class="goobers"> <img src="/images/redhots_small.gif" /> </div> i've got this (and tried a number of variations), but it isn't working:$(document).ready(function() { $(".goobers img").attr("src",$(this).replace(".","_small.")); }); of course, even if that were correct (and it's not), it would affect the file name as well (one.two.three.jpg would become one_small.two_small.three_small.jpg, but i only want one.two.three_small.jpg[/i])8/17/2011 3:08:45 PM |
Ernie All American 45943 Posts user info edit post |
This looks like a job for find/replace 8/17/2011 4:01:15 PM |
Noen All American 31346 Posts user info edit post |
^^ Use .split instead, then append between the last split and the rest. (pseudocode below)
.split(foo);
for(i to foo.length-1) foostring+=foo[i];
footstring+= "_small"+foo[foo.length]; 8/17/2011 4:19:50 PM |
Stein All American 19842 Posts user info edit post |
$('.goobers. img').each(function(){ $(this).attr('src', $(this).attr('src').replace(/\.([^\.]+)$/, "_small.$1")); });
[Edited on August 17, 2011 at 4:24 PM. Reason : The solution to this, and every problem, is "regular expressions"] 8/17/2011 4:21:23 PM |
Noen All American 31346 Posts user info edit post |
ahh, wasn't sure if the standard JS .replace supported regex strings.
How performant is regex in javacript? 8/17/2011 4:31:43 PM |
Lionheart I'm Eggscellent 12775 Posts user info edit post |
USE PERL!!!!!!OMGWTFBBQ! 8/17/2011 4:33:24 PM |
Stein All American 19842 Posts user info edit post |
Quote : | "How performant is regex in javacript?" |
Undoubtedly less taxing than cycling through the DOM based on a class.8/17/2011 5:24:46 PM |
Noen All American 31346 Posts user info edit post |
^ I was referring to our two solutions. Unless JS does some really damn good runtime optimization of regexes, it's probably considerably faster to use a split + iterate + join approach.
(this is btw a theoretical question, in any normal volume web service it probably doesnt make any difference at all) 8/17/2011 9:34:15 PM |
Stein All American 19842 Posts user info edit post |
If we're really looking for speed, it's probably quicker to use lastIndexOf() and substring().
Realistically, I don't think it makes a huge difference in speed, unless you're using IE6 on a P3. 8/17/2011 10:23:06 PM |
quagmire02 All American 44225 Posts user info edit post |
Quote : | "$('.goobers. img').each(function(){ $(this).attr('src', $(this).attr('src').replace(/\.([^\.]+)$/, "_small.$1")); });" |
perfect...thanks!
also, why did you put a period after the class? it works without it, but i wasn't sure if i was missing something8/18/2011 8:16:57 AM |
Stein All American 19842 Posts user info edit post |
Just a typo. No period needed. 8/18/2011 8:29:57 AM |
BigMan157 no u 103354 Posts user info edit post |
if you're already using a js framework, worrying about the performance hit of .replace() is silly 8/18/2011 8:52:45 AM |
qntmfred retired 40726 Posts user info edit post |
bump 3/21/2012 9:26:14 AM |
quagmire02 All American 44225 Posts user info edit post |
okay, so an outside group developed some data logging software to run with some customized equipment that we have...i suppose "data logging" isn't really correct, though, as nothing is logged
they've provided me with some jQuery to output the data on demand (it's simply for display purposes), but i would like to start dumping that data into a database
they cannot (will not) provide the data in any other way (ie. simply dump the data into the database at a given interval)...i can only run the jQuery to get the values, so i was thinking of running a cron at a given interval and passing the data from jQuery to a PHP script that would in turn insert the info into a table
i realize that this is far from ideal, but it's what i've got to work with...so what's the best method? something like the below for the .js file $.get("putindatabase.php",{value1:"mydata",value2:+info.type,value3:+info.title,value4:+info.value}); and then this for the php script?$value1 = $_GET['value1']; $value2 = $_GET['value2']; $value3 = $_GET['value3']; $value4 = $_GET['value4']; $query = "INSERT INTO table (value1, value2, value3, value4) VALUES ('$value1', '$value2', '$value3', '$value4')"; seems too easy, so i assume that's wrong...i can't test it right now, so i thought i'd post and let you all tell me how dumb i am
[Edited on March 21, 2012 at 10:10 AM. Reason : correction]3/21/2012 10:09:04 AM |
CaelNCSU All American 7082 Posts user info edit post |
I'm confused. Where do value1,etc... come from. Could you do a curl on the PHP endpoint and get the data?
[Edited on March 21, 2012 at 11:53 AM. Reason : a] 3/21/2012 11:50:51 AM |
Noen All American 31346 Posts user info edit post |
^^There's a lot easier way to do this on the fly.
Your PHP script works as is (but remove the .get) On the jQuery side, simply add a command to initiate a post http://api.jquery.com/jQuery.post/ So whenever the data is displayed, there's a postback to store it in the db.
Your way as-is will also work, if the data is really just being stored for backup/future consumption rather than immediate reuse. (And your choice is much less taxing on bandwidth and the db as well). 3/21/2012 12:34:56 PM |
BigMan157 no u 103354 Posts user info edit post |
cron's not going to execute javascript
if they gave you the jquery to output the data, presumably there's an ajax call in there somewhere to retrieve it from where they are generating it
just parse/cron that 3/21/2012 1:15:30 PM |
EuroTitToss All American 4790 Posts user info edit post |
^ 3/21/2012 1:46:30 PM |
quagmire02 All American 44225 Posts user info edit post |
Quote : | "Your PHP script works as is (but remove the .get) On the jQuery side, simply add a command to initiate a post http://api.jquery.com/jQuery.post/ So whenever the data is displayed, there's a postback to store it in the db." |
derp...my bad...i knew that
Quote : | "cron's not going to execute javascript
if they gave you the jquery to output the data, presumably there's an ajax call in there somewhere to retrieve it from where they are generating it
just parse/cron that" |
i should have realized this from the beginning...so this is what i've got in the .jsfunction getData() { $.ajax({ type: "GET", url: "http://stinkycheese.net:1234/api/bananaphone", contentType: "application/json; charset=utf-8", data: {dataTypes:['value1_total','value2_total','value3_total','value4_total']}, dataType: 'json', success: function(json_data) { if(json_data) { var datastuff = json_data.results; $.post(this,{postdata:datastuff},function(data){ alert(data); }); } }, }); } $(document).ready(function() { getData(); }); i'm trying to post it to the same document (hence the "this" instead of a URL or separate file reference) and this is in the body:<?php // get and display json data $oystersandwich = json_decode($_GET['data']); echo $oystersandwich; ?> and it keeps crashing the browser 3/22/2012 9:29:06 AM |
Stein All American 19842 Posts user info edit post |
"in the body" of what?
This isn't a jQuery problem. Curl the URL they gave you with PHP. Take results and put them into database.
Nothing client-side required. 3/22/2012 10:25:45 AM |
Ernie All American 45943 Posts user info edit post |
What the fuck 3/22/2012 2:42:48 PM |
CaelNCSU All American 7082 Posts user info edit post |
^^
Looks like the best option to me.
Quote : | ""cron's not going to execute javascript" |
He could write a node shell script 3/22/2012 5:24:15 PM |
Noen All American 31346 Posts user info edit post |
Stein is right, I was being dumb.
Just pull http://stinkycheese.net:1234/api/bananaphone straight into your PHP script, there's no purpose to using jQuery on the client as an intermediary. 3/22/2012 5:32:14 PM |
CaelNCSU All American 7082 Posts user info edit post |
url="http://stinkycheese.net:1234/api/bananaphone";curl -d "`curl $url`" $url
Should work. 3/22/2012 6:01:42 PM |
quagmire02 All American 44225 Posts user info edit post |
so yeah, cURL was exactly what i needed...i just didn't know it
this is a stupid question, but i'm happy to admit that i know little about json objects and would appreciate any help...my string looks like this (though much MUCH longer): {"results":[{"id":{"value":"abcd-1234-efgh-5678"},"name":"whatever.booger.bananaphone","point":{"id":{"value":"ijkl-9012-mnop-3456"},"name":"applesauce_nom"},"radioactive":false,"entity":{"id":{"value":"abcd-1234-efgh-5678"},"types":["Analog","Point"],"name":"whatever.booger.bananaphone"},"type":"ANALOG","unit":"kilogram"}]} after using json_decode to convert it to a json object, how do i get the values of only whatever.booger.bananaphone?4/2/2012 3:36:22 PM |
CaelNCSU All American 7082 Posts user info edit post |
In whatever language you are using: object.results[0].name
Assuming you want the first element of the results array. 4/2/2012 6:53:39 PM |
quagmire02 All American 44225 Posts user info edit post |
^ i don't...i want to get the value of all "points" with name "whatever.booger.bananaphone" 4/3/2012 8:15:02 AM |
CaelNCSU All American 7082 Posts user info edit post |
Get this: http://nodejs.org/
bananaphone.js:
fs = require('fs'); json_str = fs.readFileSync('/dev/stdin'); obj = eval(json_str); function filter(items,fn) { var results = []; for(var i = 0; i<items.length; i++) { var item = items[i]; if(fn(item)) results.push(item); } return results; }
objects_i_want = filter(obj,function(item) { if(name === 'whatever.booger.bananaphone') return true; });
curl http://myurl.com/ | node bananaphone.js
Could probably translate to any number of languages.
[Edited on April 3, 2012 at 10:21 AM. Reason : a]4/3/2012 10:20:17 AM |
quagmire02 All American 44225 Posts user info edit post |
i have a slew of yes/no radio buttons...when you click "yes" (value of 1) it shows a hidden div using the code below:
$(':radio').change(function() { var name = $(this).attr("name"); if($(this).val() === "1") { $('#'+name).show("1000"); } else { $('#'+name).hide("1000"); } }); using text links, you can select all yes, no, or clear and when you do, it successfully selects using:
$('.select-all').click(function() { var name = $(this).attr("name"); $('.'+name).each(function() { if($(this).val() === '1') { $(this).prop('checked', true); }; }); }); the problem is that the hidden div is unaffected (if you do "all yes" it should show all of the boxes, "all no" should hide them)
i'm sure this is a common enough issue and the solution (or correct way of doing it) is obviously, but i am sucking at google and jquery today
[Edited on February 18, 2014 at 2:35 PM. Reason : code]2/18/2014 2:32:54 PM |
BigMan157 no u 103354 Posts user info edit post |
change $(this).prop('checked', true); to $(this).prop('checked', true).trigger('change'); 2/18/2014 2:48:38 PM |
quagmire02 All American 44225 Posts user info edit post |
perfect! repped...?
seriously, thanks!
EDIT: the clear function isn't taking it
$('.select-clear').click(function() { var name = $(this).attr("name"); $('.'+name).each(function() { $(this).prop('checked', false).trigger('change'); }); });
[Edited on February 18, 2014 at 2:53 PM. Reason : code]2/18/2014 2:50:56 PM |
BigMan157 no u 103354 Posts user info edit post |
i'd change if($(this).val() === "1") to if($(this).prop('checked')) and see if that does anything
[Edited on February 18, 2014 at 2:58 PM. Reason : in the change handler] 2/18/2014 2:57:42 PM |
quagmire02 All American 44225 Posts user info edit post |
no dice...it just breaks the "all yes" functionality 2/18/2014 3:04:43 PM |
David0603 All American 12764 Posts user info edit post |
Any of you guys use angular? Been coding in that a lot lately in conjunction with lowdash & underscore 2/18/2014 3:22:29 PM |
qntmfred retired 40726 Posts user info edit post |
^ couple posts in message_topic.aspx?topic=640853 2/18/2014 4:00:02 PM |