Jump to content

amelio

Members
  • Posts

    22
  • Joined

  • Last visited

Everything posted by amelio

  1. Thanks kicken, I think that's what I might have to do. It's a real pain as to have someone click on the same option seems useful in some circumstances. It's very frustrating because it works fine as it is in ie and ff. I'm trying to think around the possibility that when any option in the selection list is clicked then returning the value of that option and if that value equals random_20 then firing the function. It still wouldn't work with .change because if the user was clicking the same option succesively then there is no change event. Thank you also fastol, the problem with your solution is that we never fire the $('#sel_list').change(function() because if a user clicks the same option there is no change event.
  2. Hi, I have a select list, when a user chooses random_5, if they don't like the choice that is automatically made I would like them to be able to choose this option again. The problem is Chrome doesn't recognise .click on the option element on line 48 of the fiddle. It is well documented on this and other sites that you should use .change on the select element. The problem for me is, if a user chooses random_5 after having chosen it before there is no change and the event isn't fired. I have a fiddle http://jsfiddle.net/4gEFh/2/ Any help greatly appreciated. <select id="sel_list"> <option value="clear_all">Clear All</option> <option value="select_all">Select All</option> <option value="random_5">Random 5</option> </select> <br/> <br/> <input type="checkbox" value="ruddy" /> Ruddy<br/> <input type="checkbox" value="garrido" /> Garrido<br/> <input type="checkbox" value="bennett" /> Bennett<br/> <input type="checkbox" value="johnson" /> Johnson<br/> <input type="checkbox" value="pilkington" /> Pilkington<br/> <input type="checkbox" value="wolfswinkle" /> Wolfswinkle<br/> <input type="checkbox" value="hooper" /> Hooper<br/> <input type="checkbox" value="fer" /> Fer<br/> <input type="checkbox" value="snodgrass" /> Snodgrass<br/> <input type="checkbox" value="martin" /> Martin<br/> <script> $(document).ready(function(){ $('#sel_list').change(function() { if ($(this).val() === 'clear_all') { $('input[type="checkbox"]:checked').removeAttr('checked'); } if ($(this).val() === 'select_all') { $("input[type=checkbox]").prop('checked', true); } }); }); $(document).ready(function(){ function getRandomArrayElements(arr, count) { var randoms = [], clone = arr.slice(0); for (var i = 0, index; i < count; ++i) { index = Math.floor(Math.random() * clone.length); randoms.push(clone[index]); clone[index] = clone.pop(); } return randoms; } //Dummy array function createArray(c) { var ar = []; for (var i = 0; i < c; i++) { ar.push(i); } return ar; } //check random checkboxes function checkRandom(r, nodeList) { for (var i = 0; i < r.length; i++) { nodeList.get(r[i]).checked = true; } } //console.log(getRandomArrayElements(a, 10)); $(function() { var chkCount = 10; //this can be changed var numberOfChecked = 5; $("option[value=random_5]").on('click',function(e) { var chks = $('input[type=checkbox]'); chks.attr("checked", false); var a = createArray(chkCount); var r = getRandomArrayElements(a, numberOfChecked); checkRandom(r, chks); }); }); }); </script>
  3. Hi, I have a domain registered for a client pointing to a holding page. The strange thing is I can't access it from home where my isp is aol, I have cleared the browser cache, cleared router cache but still to no avail. I can access the site on my mobile over the network but not when it is connected to the wifi. I contacted aol customer support and they couldn't access the site either. He told me that they don't use aol as their isp there but I guess they might well be using aol nameserver information. I don't know. If any one can shed any light on this I would be very grateful. The site is www.cidervinegarhealth.net Thanks
  4. Hi, I have a page with a long list of names (c1000) each with an id. On that page I would like to have a form into which i put the id number, when the form is submitted it will take me to the anchor point for that id. The question I have is, how, when i press submit and reload the page, how can I then have that form input as a anchor in the url that will then take me to the place I want to go on the list when the page loads. I can do it manually no problem by adding the hash tag and id to the url myselft it takes me there but It's a pain to do this every time. I would like to use a form. Is this possible? any help appreciated. Thanks
  5. Thanks jcbones, that's cleared it up, how strange.
  6. I found a listing that gets the right answer... $date1 = new DateTime("2009-10-11"); $date2 = new DateTime("2009-10-13"); $interval = $date1->diff($date2); echo "difference " . $interval->y . " years, " . $interval->m." months, ".$interval->d." days "; I'm not sure how 'm' gives the months remaining after the years have been calculated and 'd' also knows the remainder of days after months have been accounted for but it works that's the main thing. I'm wondering if the original listing didn't work because I am on a windows machine.
  7. I copied and pasted the code below from php manual, http://www.php.net/manual/en/datetime.diff.php, I should have got the result of '2' as they did but I got the result of '6015'. I can't think why this would be. Any help appreciated. $datetime1 = new DateTime('2009-10-11'); $datetime2 = new DateTime('2009-10-13'); $interval = $datetime1->diff($datetime2); echo $interval->format('%R%a days');
  8. Thanks Vista86 I appreciate your help but that hasn't solved my problem. I am creating a simple script for myself so that I can put in hourly rates. When I first load the page, no problem, the fields aren't set so the script doesn't try to access the array. The problem occurs when the form is submitted with no fields populated. Shouldn't the incoming array test false for isset?, it doesn't. I understand that form input of type="text" always comes in as a string. So even when the fields are empty my tests show that the array is not empty even though each element of that array is empty. I have stripped the script to the bones to show the problem area. In the real script, if the incoming array is set then I call a function which uses the array. I also have a value attribute on the input element to redisplay the values. <?php if (isset($_POST['hourly_rate'])) { $hourly_rate = $_POST['hourly_rate']; echo "\$hourly_rate is set"; } ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p>Hourly Rates</p> <?php for ($a=1;$a<=5;$a++) { ?> <input type="text" name="<?php echo "hourly_rate[]"; ?>" /> <?php } ?> <br/><br/> <input type="submit" value="Send" /> </form> [code=php:0] [/code] When I submit the form with empty fields and pass the array to a testing function I get the following output. print_r for Array Array ( [0] => [1] => [2] => [3] => [4] => ) var_dump for Array array(5) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(0) "" [3]=> string(0) "" [4]=> string(0) "" } Array is not empty Array is set index [0] is empty index [0] is set index [1] is empty index [1] is set index [2] is empty index [2] is set index [3] is empty index [3] is set index [4] is empty index [4] is set I know that it is correct that each element of the incoming array would test true for empty, as an empty string is empty, and true for isset because a variable with an empty string is still considered to be set. What I can't understand is that it shows the array as a whole is not empty and isset. So neither test will prevent my script from trying to access the array and when it does I get errors. This must be such a common thing, am I missing something really obvious here? I've searched this site and others and cannot find any answers. There is much information on single variables coming in but not arrays so it seems. Very grateful for any assistance. Thank You p.s Just noticed on the preview that it doesn't display the results for index[0] properly but it is the same as the other indexes.
  9. Hi, There is probably a very simple answer to this but I'm darned if I know it. If I have a form field coming in to the script as an array... for ($a=1;$a<5;$a++) { <input type="text" name="<?php echo "var_name[$a]"; ?>" /> } I check the input with... if (isset($_POST['var_name'])) { $var_name = $_POST['var_name']; function_call ($var_name); } So I am passing the incoming array to the variable name and then using that variable as a parameter in a function call that only occurs if the form input is set. The trouble is, because text fields come in as empty strings the input will always test positive for being set if someone submits empty form fields. So then I tested it to see if it was empty. Each element of the array is positive for being empty but the array itself is not empty because it is populated with empty strings. So I am in fact using an uninitialized variable in the argument and that is causing an error. I've searched for an answer to this but to no avail. It must be such a common thing to have arrays coming in like this so I would be grateful if someone could cast some light on it for me so that if all of the elements of the array are empty then it fails the test. Much appreciated. Thank You
  10. I think the problem boils down to the javascript sliding tab that I have. I'm no expert at javascript and wanted a simple tab script so looked around and found one. except it's a bit more complicated than I originally wanted but has a cool sliding effect. I plugged my php into that and I have this problem. When i revert back to the older design, like you, the code works no problem. I still can't understand why the javascript would cause this. It's so weird I tested a form input of "£3.24" and it told me it was a string with 6 characters. This seemed very strange as it only had 5. So, I displayed the value of each of the string elements and the first two of the six was that FFFD character, so not only was that character replacing the sterling "£" character I also had a phantom character that was not displaying but was being captured by var_dump. I think I will ditch the cool javascript effect, it costs me too much hair! Appreciate the help given and if anyone knows what the heck is going on here I would be fascinated because I would love to know why I've lost a sunday I won't get back!
  11. Thanks for that Premiso but to no avail. I even tried this if (strpos($val,"£") == 0) { $val = str_replace ("£","",$val); $val = (float) $val; }; I thought if I explicitly cast the input to a float then that might help rid me of the darn character but still no. Tearing my hair out on this one. Appreciate your help though.
  12. Thanks for that. I tried substr() and couldn't get that to work. I should have explained myself better. Sometimes I do have just numeric values coming into the form and other times with the "£" prepended. Also I did try to use "&#163;" but then it wasn't finding the match to replace with empty quotes. I was getting "£3.24" in to str_replace and the same out. I just don't get where the FFFD character is coming from. If I knew what character FFFD represented I guess I could run a second str_replace to replace that but when I paste that character into the code I just get a small one character size box.
  13. Hi, I am having a problem when bringing in form input with the sterling character (£) prepended. I want to strip the character so I can then use the integer. $val == "£3.24" $val = str_replace ("£","",$val); This code returns "�3.24" and not "3.24". I don't understand why. I have looked around and people suggest the need to use... <meta http-equiv="Content-type" content="text/html; charset=UTF-8" /> I have run the script with and without to no avail. Very grateful of any help
  14. Thanks so much Catfish, that is it. I do normally concatanate variables but as I was echoing html I didn't think about it. I'm still trying to get my head round it though. It seems that when you just include the variabe in the string without concatenation it tells you what the variable is but when you take it out of the string it replaces the variable with the value. Thanks again.
  15. Hi, I am trying to bring form input into a multidimensional array. The way I have constructed the code seems to make sense to me as it would create an array for each table row. The result i get from submitting a few numbers is the attached image. I don't understand the result I am getting. If I insert a value into the into the first input of the table it should create a value in $input_array[1][1] which I then want to insert as the value in the same input field. Any help greatly appreciated. <?php if (isset ($_POST['input_array'])) { $input_array = $_POST['input_array']; }; ?> </head> <body> <?php $rows = 10; $cols = 5; echo "<table>"; for ($a=1;$a<=$rows;$a++){ echo "<tr>"; for ($b=1;$b<=$cols;$b++){ echo "<td> <form method=\"post\"><input type=\"text\" name=\"input_array[$a][$b]\" "; if (isset ($input_array[$a][$b])) { echo "value=\"$input_array[$a][$b]\" "; }; echo "/></td>"; }; echo "</tr>"; }; echo "</table>"; echo "<input type=\"submit\" value=\"submit\"/></form>"; ?> [attachment deleted by admin]
  16. Thanks for that abazoskib, I will play around. I am hoping that by including the directory name in the constant as you have done, that will make it possible for me to identify the current page link so that I can style that. I will post back in a few days. Appreciate the time you spent to help me.
  17. I sat down for a good half hour trying to get my head around your solution abazoskib but to no avail. I'm sure this is a reflection on my lack of understanding rather than your explanation. I would need to see an example to get it. I have come up with a solution which allows me to include the same file in every page on the site but I just have to use an absolute path to that include file. So not fully satisfactory. I do the test because the site on the testing server is in a folder below the root. if ($_SERVER['SERVER_NAME'] == "localhost") { $testing = "/testing_folder"; } else { $testing = ""; }; echo "<ul id=\"main_nav\"> <li><a href=\"".$testing."/index.php\">Home</a></li> <li><a href=\"".$testing."/welcome.php\">Welcome</a></li> <li><a href=\"".$testing."/emails.php\">Emails</a></li> <li><a href=\"".$testing."/news/index.php\">Village News</a></li> </ul>";
  18. Thanks abazoskib, Using your example. If I am in Directory B, ../test.txt allows me to get to test.txt in Directory A but if I am navigating to test.txt from within Directory A I would only need test.txt & not ../test.txt. This is my problem, how do I accomodate these multiple relative addresses within one include file? This example shows just two but in a larger site you might have multiple nested directories with many files named index.php.
  19. Hi, I need a navigation include that can deal with directories at different levels on a site. All I can seem to find are the basic includes for files all in the same directory. This doesn't work for me because as soon as you navigate to a page in a nested directory the relative links don't work. Is the only option for me to use absolute links? This would cause difficulty as I would need different addresses to achieve the same result on the testing server and remote site. I also need to be able to identify the current page to style the link. At the moment I am using the code below which is fine whilst everything is in the same directory but introduce nested directories and some links will be reachable with just the $base. But only as long as current page and destination page are in the same directory. $base=basename($_SERVER['PHP_SELF']); $menu=preg_replace("|<li><a href=\"".$base."\">(.*)</a></li>|U", "<li class=\"current\">$1</li>", $menu); echo $menu; I would greatly appreciate your help.
  20. Thanks rhodesa, I did wonder if it was worth getting in too deep learning dba as most people seem to go with mysql. I notice SQLite is bundled with wamp. On the other hand dba seems a very good solution for a site that requires minimal database functionality. I would still like to be able to get it to work so it's there if I need it.
  21. Hi, I’m learning php, studying a chapter on dba. When I try to create a simple db, the db file is being created but I’m not able to access it with dba commands, the error I get is… Warning: dba_open(c:/test.db,c) [function.dba-open]: Driver initialization failed for handler: db3: Permission denied in C:\ listing12.2.php on line 39 My book uses the gdbm dbm, it says it is commonly available. However when I check my wampserver2 setup I only have the following dbm’s available to me… array(5) { [0]=> string(3) "cdb" [1]=> string( "cdb_make" [2]=> string(3) "db3" [3]=> string(7) "inifile" [4]=> string( "flatfile" } Searching, I noticed that db3 seems to be in common use so I try that first with the above result, I also get the error when I use ‘cdb’ or ‘cdb_make’ I succesfully created a database using ‘flatfile’ but my textbook explains that this dbm is for backwards compatability and is discouraged. I guess my success with this dbm at least proves that I have the correct permissions. I am running wampserver2 (php 5.2.6, apache 2.28). If you could help me I would be very grateful. Here is the code in full... <?php $dbh = dba_open("c:/test.db", "c", "db3") or die( "Could not open database" ); dba_replace( "product_01", 25.20, $dbh ); dba_replace( "product_02", 56.50, $dbh ); dba_replace( "product_03", 73.50, $dbh ); dba_replace( "product_04", 19.50, $dbh ); ?> <table > <tr> <td>product</td> <td>price</td> </tr> <?php $key = dba_firstkey( $dbh ); while ( $key != false ) { $value = dba_fetch( $key, $dbh); print "<tr><td> $key </td>"; print "<td> \$".sprintf( "%01.2f", $value )."</td></tr>"; $key = dba_nextkey( $dbh); } dba_close( $dbh ); ?> </table>
×
×
  • 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.