Jump to content
Larry Ullman's Book Forums


  • Posts

  • Joined

  • Last visited

zibrnp's Achievements


Newbie (1/14)



  1. Hello, I have PHP file (file1.php) asking for a date: echo '<form action="charts.php" id="form_chart_date" method="post"> <div id="form_chart_date"> <p>Please select date. </p> <p><input name="date_looking" type="text"> <input type="submit" value="Display data" name="display_chart"></p> </div> </form>'; After submission file1.php handles the process but there is reference to JavaScript file which reads PHP generated JSON file. JavaScript file looks like: (document).ready(function() { var date = "<?php echo json_encode($_POST); ?>"; $.ajax({ data: {date_looking: date}, url: "http://localhost:8888//live_site_local/www/json.php", dataType: "JSON", type: "POST", cache: false, success: function(pieData) { var ctx = $("#chart-area").get(0).getContext("2d"); new Chart(ctx).Pie(pieData); } }); }); If I replace variable date with something like: var date = "2015-01-01"; then everything works ok. It looks like the problem is that I can not pass PHP $_POST array to JavaScript. Here is the line from PHP file (json.php) that generates JSON object. $date_looking = $_POST['date_looking']; Does anyone know what I am doing incorect? Thanks
  2. Hello, I have a problem with a form I created. The form should load one row of fields (first name, last name and Date). When someone clicks on Date then jQuery date picker should display calendar. Until this point everything works perfectly ok. I also have a button that adds another row of the same fields (first name, last name and Date). The button adding new row works ok but calendar from jQuery date picker is not working in that newly added field. Can you guys take a look what might be wrong with my code please… Thanks, T $(document).ready(function(){ var x=0; $("#datepicker").datepicker({dateFormat: 'yy-mm-dd'}); $("#add").click(function(){ x++; $("#name_data").append('<p>First Name: <input name="name['+x+'][first]" type="text"> Last Name: <input name="name['+x+'][last]" type="text"> Date: <input id="datepicker" name="name['+x+'][date]" type="text"> <input id="remove'+x+'" type="button" name="remove" value="remove"></p>'); $("#remove"+x).click(function(){ $(this).parent('p').remove(); }); }); }); <form action="test.php" method="post"> <div id="name_data"> <p>First Name: <input name="name[0][first]" type="text"> Last Name: <input name="name[0][last]" type="text"> Date: <input id="datepicker" name="name[0][date]"></p> </div> <p><input id="add" type="button" name="add" value="Add more"></p> <p><input type="submit" name="submit" value="Submit..."></p> </form>
  3. Hello, I have small problem with script 13.1, particularly with step 5. Book explains that this code: $value = str_replace(array("\r", "\n", "%0a", "%0d"), ' ', $value); is going to create new value that is free of newline characters. It is true when I enter to the form string with "%0a" and "%0d" but it is not true for "\r" and "\n". When entering email "test@test.com\n" it creates "test@test.com\\n" (it adds backslash). Does anyone know why this is happening? Thanks for any suggestion.
  4. I am 100% sure I am looking at the correct cookie. No matter how I set expiration parameter it always says "Session". If I set expiration to time()+60 it actually expires after 60 seconds and I am not able to see restricted content. So it works but I do not see this value when I view cookie.
  5. Hello, I have been working on script 12.5. which allows to set cookie's parameters. As the example in the book shows, I wanted to set cookie that expires within 1h from creation. setcookie('user_id', $data['user_id'], time() + 3600, '/', '', 0, 0); When checking the cookie after successful signing-in, Expires: always says Session. Why is that? Thank
  6. OMG I can not believe I forgot that it returns array (the same mistake again) . Anyway thank you very much. T
  7. Hello I want to change value of a href label and need to reference it using class name. I did: <html> <head> <title>test</title> </head> <body> <a class="class_id" href="#">Older Post</a> </body> <script type="text/javascript"> window.onload = init; function init() { 'use strict'; var to_replace = document.getElementsByClassName('class_id'); to_replace.innerHTML = "Older"; } </script> </html> When using in html id and getElementById everything works but not with getElementsByClassName. Can you guys suggest solution please? Thanks T
  8. Thanks for the answer… Yes it does, It's described on page 245 of the book in "Functions as Variables Values" paragraph. Basically in this line "bidAjax.onreadystatechange = handleBidAjaxResponse;" we are assigning value of function "handleBidAjaxResponse" to the property "onreadystatechange" of the object bidAjax. Am I right? Thanks
  9. Hello, I'm going over the "view.js" file on page 585 and in point 12 we have: "bidAjax.onreadystatechange = handleBidAjaxResponse;" why "()" is missing in the function call? Why it is not like this: "bidAjax.onreadystatechange = handleBidAjaxResponse();" Thanks
  10. Hello, I have been working on a "quote" example, Chapter 11 page 468. I am using MAMP as local server environment. The example from the book was not working with "quote.php" file so I run the file via local server and blank page was returned. Any suggestion in regards to what I am doing wrong please? I have created "quote.json" file with exact content google's URL returns and that is working. Thanks, T
  11. Hello, I have been testing code on page 478 step 2 and don't understand why there is "error.message" instead of "ex.message"? try { ajax = new ActiveXObject('MSXML2.XMLHTTP.3.0'); } catch (ex) { console.log('Could not create the ActiveXObject: ' + error.message + '\n'); } Maybe the answer is simple but it bothers me a lot Could anyone help me understand it, please? Regards, T
  12. Hello, Thank you very mach for the explenation. Tom
  13. Hello Guys, I have been going over the book and wanted to do small exercise..., where I have form with three radio buttons and when clicking each one I am alerted (alert() method) with the value of the radio button. HTML markup looks like: <form action="#" method="post" id="theForm"> <fieldset><legend>Select Radio Button</legend> <div> <p> <input type="radio" name="options" id="a1" value="a1"> a1 <input type="radio" name="options" id="b2" value="b2"> b2 <input type="radio" name="options" id="c3" value="c3"> c3 </p> </div> <div> <p id="res"></p> </div> <input type="submit" value="Submit" id="submit"> </fieldset> </form> JavaScript Code: window.onload = function () { 'use strict'; document.getElementsByName('options').onchange = displaySelection; //document.getElementById('a1').onclick = displaySelection; //document.getElementById('b2').onclick = displaySelection; //document.getElementById('c3').onclick = displaySelection; }; function displaySelection() { 'use strict'; var selection = document.getElementsByName('options'); var result; for (var i = 0, count = selection.length; i < count; i++) { if (selection[i].checked) { result = selection[i].value; alert(result); break; } } } It works perfectly when using onclick event with reference to the id (three lines commented at the beginning) but it does not work when I refere to the element by name… with event onchange or onclick. Can you guys explain why is that? Thanks, Tom
  • Create New...