Jump to content
Larry Ullman's Book Forums

Adrian56

Members
  • Posts

    21
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by Adrian56

  1. Thanks team. Nice to get help in context. Antonio, am I correct in thinking that 'toggle' latches i.e. it remembers which state it was at even if you are returning to the selected element having done multiple tasks in-between which affected the elements targeted by the 'toggle'?
  2. Sorry I was in the midst of formatting it in the form - hit a shift key or something - and the post was sent before it was ready or I had re-read it. The var filterB= $(this).attr([id]) was the Boolean I was trying to make work - I still can't but would love to know the error in my syntax so that in the future I can extract the 'id' attribute when in jQuery. The work-around was to use var filterB = $(this).attr('title'); instead.
  3. I was trying to filter the event using the id == 'sunnyvidicon' as my Boolean for 'it's a video'. I still can not get the syntax correct to set a variable var filterB= $(this).attr([id]) - when I set a flag it just told me the var was undefined. so.... I used var filterB = $(this).attr('title'); and it works perfectly! The code is below - any improvements welcome..... .....but I'd still love to know the syntax that gets a useable value out of $(this).attr([id]) - I'm sure I shall need it in the future. Thank you // alt Sunny functions $(document).ready(function(){ //set environment $('#sunnyvideo').addClass('hidden'); var vidurl = $('#sunnyvideo').attr('src'); $("h2").append('<em></em>'); $(".sunny a").click(function(){ //set flag - remove when working! var filterB = $(this).attr('title'); // alert("flags have values : " + filterB + "\n" + vidurl); // Is cameraIcon is clicked ? if (filterB == 'camIcon') { //set flag - remove when working! var iconClicked = true; // alert("Camera icon clicked : " + iconClicked); //show iFrame hide Gallery large picci $('#sunnyvideo').removeClass('hidden').attr('src', vidurl), $('#Sunny').addClass('hidden'); //get the attributes var largePath = $(this).attr("href"); var largeAlt = $(this).attr("title"); // set the attributes $("#Sunny").attr({ src: largePath, alt: largeAlt }); $("h2 em").html(" (" + largeAlt + ")"); return false;; } else { //hide iFrame show Gallery large picci $('#sunnyvideo').addClass('hidden').attr('src', ''), $('#Sunny').removeClass('hidden'); var largePath = $(this).attr("href"); var largeAlt = $(this).attr("title"); $("#Sunny").attr({ src: largePath, alt: largeAlt }); $("h2 em").html(" (" + largeAlt + ")"); return false; } }); }); //end of alt Sunny function
  4. In fact $(".sunny a [id=sunnyvidicon]") gets exclusivity in case I 'id' another thumbnail
  5. I've found a selector that works for the camera icon $(".sunny a [id]") I just need the syntax for not([id]) ie excludes $(".sunny a [id]")
  6. Your second point: I only have Safari. I guess I need to try more browsers!
  7. On my working page, the viewer selects the large picture by clicking on the small images(thumbnails) lined up below. One of those thumbnails is a camera icon & link to the iFrame(an embedded video) which replaces the large picture on the web page. To change between still pictures you just click on the next small image - but to leave the iFrame you need to click on the camera icon a second time i.e. it toggles the visibility of the iFrame and main picture element. I am trying to change the UI so that just clicking on the next thumbnail toggles the visibility of the two main elements as well as changing to the chosen image. By commenting out $('#sunnyvideo').addClass('hidden'); and having just one of the event handlers working with no filtering applied, each handler has shown the functionality I want. I can't get the jQuery filtering to work and so identify if it was the camera icon which was clicked. It would then use the appropriate event handler and give the viewer the expected UI and image on the page. It's my first venture into jQuery having read the chapter in Larry's book. This is my review & pursue!
  8. I have set up a picture gallery in which one of the elements is a video in an iFrame. It worked and I was happy until someone said "Why do you have to hit the camera icon again to escape from the video?' Obvious and exactly what I strive towards - really simple UI. I tried to code the simpler interface. I have proved sections of my code by 'commenting out' individual lines. I believe it is the selector filtering which is failing me - AND IT'S DRIVING ME CRAZY! Please can you tell me 'the error of my ways, thank you. The HTML : <div class="twocol_pad30"> <iframe id="sunnyvideo" class="sunny" type="text/html" src="https://www.youtube.com/embed/_xxxxxxxxxxx?modestbranding=1" frameborder="0" allowfullscreen></iframe> <p><img src="images/106_490.jpg" alt="Large image" id="Sunny" /></p> <p class="sunny"> <a href="images/42_490.jpg" title="Image 1" ><img src="images/42_100.jpg" alt="sunny" /></a> <a href="images/82_490.jpg" title="Image 2"><img src="images/82_100.jpg" alt="sunny" /></a> <a href="#sunnyvideo" title="cameraIcon" ><img src="camera_icon_100.jpg" alt="sunny" id="sunnyvidicon"/></a> <a href="images/95_490.jpg" title="Image 1" ><img src="images/95_100.jpg" alt="sunny" /></a> <a href="images/106_490.jpg" title="Image 6"><img src="images/106_100.jpg" alt="sunny" /></a> </p> </div> The jQuery that works but requires the camera icon to toggle to get in/out of the iFrame : // Sunny functions (2) $(document).ready(function(){ $("h2").append('<em></em>') $(".sunny a").click(function(){ var largePath = $(this).attr("href"); var largeAlt = $(this).attr("title"); $("#Sunny").attr({ src: largePath, alt: largeAlt }); $("h2 em").html(" (" + largeAlt + ")"); return false; }); }); $(document).ready(function() { $('#sunnyvideo').addClass('hidden'); var vidurl = $('#sunnyvideo').attr('src'); // hide #Sunny first $('#sunnyvidicon').toggle(function() { $('#Sunny').addClass('hidden'), $('#sunnyvideo').removeClass('hidden').attr('src', vidurl); }, function() { $('#Sunny').removeClass('hidden'), $('#sunnyvideo').addClass('hidden').attr('src', ''); }); }); // end of Sunny functions(2) The jQuery that I want to use to simplify the UI - but doesn't quite work: //alt-combined Sunny function $(document).ready(function(){ //set environment $('#sunnyvideo').addClass('hidden'); var vidurl = $('#sunnyvideo').attr('src'); //filter thumbnail events $(".sunny a:not(sunnyvidicon)").click(function(){ //set flag - remove when working! var filterB = $(this).attr('title'); alert("flags have values : " + filterB + "\n" + vidurl); //hide iFrame/show large Gallery picci $('#sunnyvideo').addClass('hidden').attr('src', ''), $('#Sunny').removeClass('hidden'); //get the attributes var largePath = $(this).attr("href"); var largeAlt = $(this).attr("title"); //set the attributes $("#Sunny").attr({ src: largePath, alt: largeAlt }); $("h2 em").html(" (" + largeAlt + ")"); return false; }); // if cameraIcon is clicked $(".sunny a:sunnyvidicon").click(function(){ //show iFrame/hide large Gallery picci $('#sunnyvideo').removeClass('hidden').attr('src', vidurl), $('#Sunny').addClass('hidden'); //get the attributes var largePath = $(this).attr("href"); var largeAlt = $(this).attr("title"); //set the attributes $("#Sunny").attr({ src: largePath, alt: largeAlt }); $("h2 em").html(" (" + largeAlt + ")"); return false;; }); }); //end of alt Sunny function
  9. I didn't have the terminology to have successfully found that link! The form now behaves totally as expected and the UI has an elegant simplicity, thank you
  10. I have been using page.html#goto to navigate to a specific location and page.html?name=value to transfer values between pages. What I have failed to do is combine both. page.html#goto?name=value and page.html?id=goto&name=value have failed for me. I'm sure the solution is simple - I just cannot find it! Help please
  11. Okay all that you have said in this and 'Trying To Return To Previous Page From A Form' has worked perfectlybut... below is the source code from the formpage being 'posted' to itself. Every thing looks as though it should be fine but the value of the message field 'dddd' is not displayed. Have I hit the edge again - I'm really not doing very well with this message field! <form method='post' action='formpage.php?urlinform=http://localhost:8888/Any_root/anotherpage.html&email=&subject=sssss&message=dddd'> <fieldset><legend>Your Contact Information</legend> Email: <input name='email' type='text' value='' tabindex='1'><br> Subject: <input name='subject' type='text' value='sssss' tabindex='2'><br> Message:<br> <textarea name='message' rows='7' cols='40' value='dddd' tabindex='3'></textarea><br> <input type='hidden' name='urlinform' value='http://localhost:8888/Any_root/anotherpage.html'> <input type='submit' id='submit' tabindex='4'> </fieldset> </form>
  12. Absolutely spot on!! I'd added spaces/breaks at that point in the coding for readability. Works perfectly now, thank you. Now I can get on with making the form sticky.
  13. I am trying to confirm entries in the form below using strlen but am stymied by a strange bug/error - in check for entries in subject and message fields else if((strlen($_POST['subject']) == 0) || (strlen($_POST['message']) == 0)) the first condition works perfectly ($length=0) but strlen($_POST['message'] returns $messagelen=5 or more even when nothing is entered?! When you first click in the textarea the cursor positions beyond the start point - which is probably causing the error, but why? Thank you for any help. <?php function spamcheck($field) { //filter_var() sanitizes the e-mail //address using FILTER_SANITIZE_EMAIL $field=filter_var($field, FILTER_SANITIZE_EMAIL); //filter_var() validates the e-mail //address using FILTER_VALIDATE_EMAIL if(filter_var($field, FILTER_VALIDATE_EMAIL)) { return TRUE; } else { return FALSE; } } if (isset($_POST['email'])) {//if "email" is filled out, proceed //check if the email address is invalid $mailcheck = spamcheck($_POST['email']); if ($mailcheck==FALSE) { $url = htmlspecialchars($_SERVER['HTTP_REFERER']); echo "<a href='$url'>Invalid form entry.<br><br> Please click here to return to form and retry.</a>"; } // check for entries in subject and message fields else if((strlen($_POST['subject']) == 0) || (strlen($_POST['message']) == 0)) { $url = htmlspecialchars($_SERVER['HTTP_REFERER']); $length = strlen($_POST['subject']); $messagelen = strlen($_POST['message']); echo "<a href='$url'>Please fill in all fields. " . $length . $messagelen . "<br><br> Please click here to return to form and retry.</a>"; } else {//send email $email = $_POST['email'] ; $subject = $_POST['subject'] ; $message = $_POST['message'] ; mail("me@example.com", "Subject: $subject", $message, "From: $email" ); $url = htmlspecialchars($_SERVER['HTTP_REFERER']); echo "Thank you for using our mail form"; echo "<a href='$url'>Click here to return</a>"; } } else {//if "email" is not filled out, display the form echo "<p><b>If you have any questions and wish to contact us,<br /> please fill in the form below.</b></p><br> <form method='post' action='formpage.php'> <fieldset><legend>Your Contact Information</legend> Email: <input name='email' type='text' tabindex='1'><br> Subject: <input name='subject' type='text' tabindex='2'><br> Message:<br> <textarea name='message' rows='7' cols='40' tabindex='3'> </textarea><br> <input type='submit' id='submit' tabindex='4'> </fieldset> </form>"; } ?>
  14. <?php $returnurl = htmlspecialchars($_SERVER['HTTP_REFERER']); if(!preg_match('/formpage.php/', $returnurl)) { echo "<p><a href=\"$returnurl\"><img id=\"lftarrow\" src=\"images/LhArrow.graphic.png\" alt=\"Previous page\">Return</a></p>"; } else { echo "<p><a href=\"index.html\"><img id=\"lftarrow\" src=\"images/LhArrow.graphic.png\" alt=\"Home page\">Return to Home page</a></p>"; } ?> I am using this code to provide a path back to the calling page from the page with a form. My problem is that the form calls its own page in <form method='post' action='formpage.php'> negating what I had hoped to be an elegant return path for the user - hence the if/else defaulting to a fixed url. Is there anyway of preserving the value of $returnurl whilst the form processes? Thank you PS Posted here as I was playing with techniques tried from this book - hope that is correct
  15. Stuck on the Login exercise in the last section of chapter 15. I've downloaded 'jquery-1.9.1.min.js' and created the calculator both with and without the 'alerts' but just cannot get the 'ajax' exercise to run. I've walked away (Larry's best solution) and usually come back to find a pesky typo has wasted days of my life but not this time. In desperation I have cut and pasted the scripts from the support pages - initially piece-meal to see where an error could be and finally in toto just to get the thing to run. I get the form up on the page with the initial error messages i.e. 'Please enter your email address!' & 'Please enter your password!' beside the forms text boxes, but that is it. Correct/Incorrect entries illicit no response. Having got jQuery working on my MAMP/OS X MAC do I have to do more to get Ajax functional? Thanks in advance for any help.
  16. Okay solved and it is embarrassingly obvious if I've got this correct. On page 121 is '/applications/mamp/library/bin/mysql' which is what I entered and got the mysql prompt. On page 122 is 'mysql -u username -p' so I entered '-u username -p' after the mysql prompt and got nowhere! Found '/applications/mamp/library/bin/mysql -u username -p' in manual and subsequently at the bottom of page 122 in the screenshot - happiness!! Hope this thread saves somebody else a lot of time.
  17. Ok, I've just proved I'm a 'Newbie"<br /><br />I have been searching the MYSQL manual and re-reading the errors. I get the initial mysql-manual SQL queries to run but if I query anything else I get "access denied ''@localhost"<br />I'm guessing that is a privileges issue - help please
  18. I use a default installation of MAMP on a macbook running OS X. I can carry out the exercises in MyPHPAdmin but when trying them from the 'Terminal' application I had issues : I can open and sign-in and enter the queries as per chpt5 but I get no response i.e. the tables (part tables) shown in the screen shots do not appear in the window. Neither am I getting any error messages. Any ideas what blindingly obvious thing I'm missing. Thank you Incidentaly, entering a semi-colon after the SQL commands in the 'Terminal' window resulted in 'syntax error' statements.
  19. Margaux Thank you. I went away and looked at a MySQL manual and found this: "If you set a column to the value it currently has, MySQL notices this and does not update it" (http://dev.mysql.com/doc/refman/5.5/en/update.html) "An integer greater than zero indicates the number of rows affected or retrieved. Zero indicates that no records were updated for an UPDATE statement, no rows matched the WHERE clause in the query or that no query has yet been executed. -1 indicates that the query returned an error or that, for a SELECT query, mysql_affected_rows() was called prior to calling mysql_store_result()." (http://dev.mysql.com/doc/refman/5.5/en/mysql-affected-rows.html) The mysql_affected_rows($dbc)= 1 is used in the script to report on the query. In the "error" conditions I was describing above, mysql_affected_rows($dbc) = 0 The problem is not in the query but the condition set to generate the error message and resetting 'mysql_affected_rows($dbc)>= 0' allows the script to cope with the situation I generated whilst catching any genuine errors. If the above is sound reasoning, I think I've got it. Onwards to chapter 13 - the last chapter!! Once again, thank you.
  20. Hi New to PHP but have got to the end of chapter 12 and all is great -almost. I was further playing after successfully creating/checking 'edit_entry.php' (script 12.9) and this time hit the 'submit' button before any change had been made to an entry. This triggered the error 'Could not update entry because: ...' i.e. mysql_affected_rows($dbc) = 0 Intrigued I played some more Any editing resulting in change successfully runs. No editing returns the error. Any editing returning to the original text returns the error. I'm having difficulty understanding when/how the script 12.9 has a memory to recognising change /non-change. I thought it was just retrieving & returning values/variables/values to from the db/form/db. Please can you point my thoughts in the correct direction for understanding! To Administrator: Your e-mail filter did not recognise my initial (valid) e-mail address
×
×
  • Create New...