Jump to content

lindm

Members
  • Posts

    199
  • Joined

  • Last visited

    Never

Everything posted by lindm

  1. Having problems creating the object structure. I want a structure like this: { "BFO": { "1": { "text1": "100", "text2": "200", "text3": "300" }, "2": { "text1": "400", "text2": "500", "text3": "600" } } } I am creating the object with an each iteration in jquery: function objects() { var BFO = new Object(); BFO["BFO"] = new Object(); $("tr").each(function(i) { BFO["BFO"][i] = new Object(); BFO["BFO"][i]["text1"]="test"; BFO["BFO"][i]["text2"]="test"; BFO["BFO"][i]["text3"]="test"; }); This generates: {"BFO":[{"text1":"test","text2":"test","text3":"test"},{"text1":"test","text2":"test","text3":"test"}]} } } Almost there but missing the 1, 2 etc and there are [] characters I don't need. Any help to complete appreciated.
  2. I have the following object: var data={ 'ID1':{ field1: 'selector1', field2: 'Text', field3: 'Text1' }, 'ID2':{ field1: 'selector1', field2: 'Text', field3: 'Text2' }, 'ID3':{ field1: 'selector2', field2: 'Text', field3: 'Text3' }, 'ID4':{ field1: 'selector2', field2: 'Text', field3: 'Text4' } }; How would I sum/join all the field3 nodes for each unique field1 node? So for instance the sum/join of selector1 would be "Text1Text2" and for selector2 "Text3Text4". Thanks
  3. Understand your point and appreciate your time and suggested solution. Thought by only needing the answer for merging two arrays, I would handle the problem of the one array. Tried your solution and it seems to work well. Many thanks!
  4. Works perfect. Minor point. I missed that the two arrays to be merged are actually part of the same array. Could this be handled easily? ARRAY Array ( [uB] => Array ([0] => Array ( [1070] => 750000.00 [1079] => -750000.00 ) ) ([-1] => Array ( [1079] => -450000.00 ) ) ) Should become Array ( [uB] => Array ( [1070] => Array ( [0] => 750000 [-1] => 0 ) [1079] => Array ( [0] => -750000 [-1] => -450000 ) ) )
  5. Stuck on merging two arrays: Got the following to arrays: ARRAY1 Array ( [uB] => Array ([0] => Array ( [1070] => 750000.00 [1079] => -750000.00 ) ) ) ARRAY2 Array ( [uB] => Array ([-1] => Array ( [1079] => -450000.00 ) ) ) Want them to merge to the following array (important as you can see that if a key is missing in one array but exists in the other it is created with the value 0) CREATED ARRAY Array ( [uB] => Array ( [1070] => Array ( [0] => 750000.00 [-1] => 0.00 ) [1079] => Array ( [0] => -750000.00 [-1] => -450000.00 ) ) )
  6. Aa alright. Just curious your second suggestion: split on any spaces except those within double-quote delimited phrases, is that a simple regex?
  7. Preferably the double quotes should be removed. As for your suggestions the best would be only the first two spaces would be the best split solution.
  8. Need help figuring out the expression to split the following string in the two first spaces: #TEXT1 1234 "Text text text text" Should become: #TEXT1 1234 Text text text text
  9. I have the function below to check if all form text fields of the selection are either zero or nothing. I realize it has the side effect that if field1 is 1000 and field2 is -1000 the functions returns the class value, which is not the purpose. Any suggestion for a script to check each text field individually it is either zero or contains nothing. If this is true for the arguments it returns the class value. Perhaps using an absolute value? function rowx() { $num = func_num_args(); //antal args $total = 0; for( $i = 0; $i < $num; ++$i ) { $total += func_get_arg($i); } if ($total = 0 || $total =='') return 'class="h"'; }
  10. Is there an way to make sure that a word in bold and the same word in normal have the same width?
  11. Great! Disabling magic quotes solved it.
  12. I read somewhere that magic_quotes will be permanently on in php6..is that correct?
  13. I have the following array which contains trailing slashes I need to remove. What is the best way to accomplish this? Array ( [Field1] => A [Field2] => Test [Field3] => öööö \'\')
  14. lindm

    preg_replace

    Solved it. $string = ' <html> <body> <table> <tr> <td><input name="KRRfield1" type="text" class="fb" id="KRRfield1" value="" /></td> <td><input name="KRRfield2" type="text" class="fb fy" id="KRRfield2" value="" /></td> <td><input name="RRfield3" type="text" class="fb" id="RRfield3" value="" /></td> <td><input name="RRfield4" type="text" class="fb fy" id="RRfield4" value="" /></td> </tr> </table> </body> </html>'; $pattern='/(<input name="KRR)(.+)(type="text" class=")(.+)(")(.+)(id=")(.+)(" value)(.+)(\/>)/'; //$pattern='/<input name="KRR.+\/>/'; $replacement="'.field($8,$4).'"; echo preg_replace($pattern, $replacement, $string);
  15. lindm

    preg_replace

    Have a html code where I want to replace certain text fields with a new string as below. My problem is that the replacement should extract the id and class from the matching string to be used in the replacement. Any suggestions? <html> <body> <table> <tr> <td><input name="KRRfield1" type="text" class="fb" id="KRRfield1" value="" /></td> <td><input name="KRRfield2" type="text" class="fb fy" id="KRRfield2" value="" /></td> <td><input name="RRfield3" type="text" class="fb" id="RRfield3" value="" /></td> <td><input name="RRfield4" type="text" class="fb fy" id="RRfield4" value="" /></td> </tr> </table> </body> </html>'; $pattern='/<input name="KRR.+\/>/'; $replacement="'.field(fieldid,class).'"; echo preg_replace($pattern, $replacement, $string);
  16. Using this instead... $(document).ready(function(){ $("*[id^=\'ST\']").click(function() { string="#"+this.id.substring(2); $.get("tips/"+this.id+".txt", function(data){ $(string).val(data); }); }); });
  17. When I change to jquery 1.3.2 it works no matter how many times I click the + sign. Is it a bug in 1.4?
  18. My code below only executes once. So after first click and I remove text from the textfield manually and click the + nothing happens. It should work whenever clicked. <html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> <script type="text/javascript" > $(document).ready(function(){ $("*[id^=\'ST\']").each(function() { $(this).click(function() { string = this.id.substring(2); string2 = "#" + string; $(string2).load('tips/'+this.id+'.txt'); }); }); }); </script> </head> <body> <a id="STtextfield">[+]</a> <textarea name="textfield" id="textfield"></textarea> </body> </html>
  19. In a form it often seems a waste of space with both the id and name attribute for a field, since they often are the same: <input name="field" type="text" id="field" value="0" /> So far both have been necessary for a form submit and for instance if I also have javascript handling of the field. I have read that in xhtml id replaces name but can't get this to work. What would be nice is if the name attribute could be removed for a input field and when the form is submitted the id becomes part of the $_POST.
  20. Understand. Since I need to use the id tag for all my text fields (jquery) each text field still needs to be unique. This is the code I currently use. Is it slow for larger forms/is there more efficient code? $_POST=array( "RRintNOcy" => "1", "RRintNOpy" => "2", "RRintVLcy" => "3", "RRintVLpy" => "4", "RRintSUMcy" => "5", "RRintSUMpy" => "6" ); function sum($name,$yr){ $total = 0; foreach ($_POST as $k => $v) { if(substr($k,0,-4)==$name&&substr($k,-2)==$yr){ $total += $v; } } return $total; } echo sum(RRint,cy);
  21. Went through the array functions at http://www.w3schools.com/PHP/php_ref_array.asp but can't find a good function for me. Code to explain: <?php $_POST=array( "RRintNOcy" => "1", "RRintNOpy" => "2", "RRintVLcy" => "3", "RRintVLpy" => "4", "RRintSUMcy" => "5", "RRintSUMpy" => "6" ); function sum() { return array_sum($_POST[only values of keys beginning with RRint and ending with cy AND not containing SUM); } echo sum(); ?> Should return 4.
  22. I am trying to make a script that does the following: Say I have x number of fields in a form named like the following: FieldA1y FieldA1x FieldA2y FieldA2x FieldA3y FieldA3x etc etc FieldASUMy FieldASUMx The script should calculate a sum for all fields with beginning with FieldA and ending with y as one sum and beginning with FieldA and ending with x as one sum. The field FieldASUMX or y should not be included in the sum. Not much I got so far: function sum($field) { $total = 0; //code return $calc[$field] = $total; } The script would be called like sum("FieldASUMx"). This would sum all fields beginning with FieldA and ending with x, however not the FieldASUMx field.
  23. lindm

    Opacity problem

    Thanks for your answers! Seems like the png is the easiest solution.
  24. lindm

    Opacity problem

    Have a problem that the text in a container also gets the opacity of the parent container. I want the opacity of the text to be 100 or 1 depending on browser. Se code below. <html> <head> <style type="text/css"> span#vtipc { position: absolute; left: 5px; padding: 16px; background-color: black; -moz-opacity: 0.75; opacity:.75; filter: alpha(opacity=75); width:400px; z-index: 9999; } span#vtip { font-size: 10px; color:#FFF; } </style> </head> <body> <span style="font-size:36px"> BACKGROUND TEXT</span> <span id="vtipc"><span id="vtip">TIP TEXT</span></span> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.