Jump to content

chibineku

Members
  • Posts

    1,278
  • Joined

  • Last visited

Posts posted by chibineku

  1. When you are giving the document.write method something to write to the page, it is enclosed in double quotes. You either need to escape the double quotes around the class or id (escaping quotes means to precede them with a backslash, so that they are interpreted literally: \") or use single quotes or backticks instead or using double quotes again. Try:

    document.write("<p class='a1'>this is some text</p>")

  2. Yes, of course. The thing is, what use is a span that mirrors the user's selection, especially if it's hidden? I don't understand the point, really. They can see what they selected, and it won't be any advantage when you're processing the form in a server side language.

  3. I tested it in w3school's tryit editor. Here is the code:

    <html><head><script type="text/javascript">function city_dropdown_changed(sel) {var index = sel.selectedIndex;var city = sel.options[index].value;el = document.getElementById("city_select");el.innerHTML = city;}</script></head><body><form action="testcode.php" method="post">	  		<select style="position: relative" id="preferred_city" name="preferred_city" onchange="city_dropdown_changed(this)">			<option value="New York">New York</option><option value="London">London</option><option value="Paris">Paris</option><option value="Berlin">Berlin</option><option value="Rome">Rome</option></select></form><span id="city_select" style="margin-bottom: 10px; font-size: 32px;"></span></body></html>

    That all works, anyway.

  4. It's tidiest to put all your scripts in the head tags, at the top of the page. I just meant that if you try to reference an element in the head it has to be be in a function that will fire after the page has loaded, otherwise the element won't exist yet.You should never have two elements with the same id. Your select should have an id, and the span a different one. The span id is needed inside the script to find it on the page and to change it's innerHTML. If you have to elements with the same id, the script might try to change the innerHTML of the select element or something else unexpected. The id of the select is not important in this script, because when you call the function that updates the span with the newly selected it, you pass a reference to it with the use of the word 'this'. When the function is called, the reference to the select is stored in the variable sel (the bit between the brackets). We then create a reference to the span with document.getElementById('preferred_city'). So, try changing the select name to city_select or something and give it another shot.

  5. Okay, again, use the proper script tags. Assigning the function to a variable like that makes the function fire straight away, which you don't want. Try:

    <script type="text/javascript">function city_dropdown_changed(sel) {var index = sel.selectedIndex;var city = sel.options[index].value;el = document.getElementById["preferred_city"];el.innerHTML = city;}</script>

    But as I said you need to change the id of the select to something else for this to work - two elements with the same id won't do what you expect.

  6. Well, there's no function called city_dropdown_changed(), so how do you expect the span to be updated if there's no function to do it? Also, having a bit of JavaScript that immediately makes the span innerHTML = '' isn't going to work if the JavaScript appears above the element you wish to target, as it doesn't yet exist in the DOM when you try to make a reference to it. You should also use the canonical <script type="text/javascript"> opening script tag, and not just <script>.Also, you have two elements with id preferred_city - ids are unique, so you need to call one of them something else.

  7. Hm. PHP is processed before HTML (confusingly, it is supposed to stand for Hypertext Pre-Processor - surely that would be HPP?). So a variable stored in PHP has to be dropped into HTML or JavaScript first. For example, say you have a div that holds the PHP variable, you would do something like:

    <div id="comment"><?php echo $pr['comment']; ?></div>

    In the CSS, you would put:

    #comment {display: none;}

    to hide it.You would need to put this in the CSS to make the div appear when you hovered over the link:

    a.popup :hover #comment {display: block;}

    I would suggest giving the link an id instead of a class, as surely you only want one trigger to make the div appear. If you wanted an actual popup, you would need to use JavaScript, something like:

    <script type="text/javascript">var comment = '<?php echo $pr['comment']; ?>';document.getElementById('popup').onmouseover = alert(comment);</script>

  8. RewriteEngine On#Translate default page to rootRewriteCond %{THE_REQUEST} ^GET\ .*/index\.(php5|html|php)\ HTTPRewriteRule ^(.*)index\.(php5|html|php)$ /$1 [R=301,L]#Translate http://www.xyz.com/index.php?page=contact-us  -> http://www.xyz.com/contact-us.htmlRewriteRule ^/(.*)\.html$ //page=$1

    Put that in a file called .htaccess and save it at the webroot. I haven't tested the second one, but it should be ok.

  9. Returning true or false isn't always necessary, but it can have a variety of effects.For example, if I attach an onsubmit event handler to a form submit button, if I return false at the end of my handler function, the form won't submit. When an event handler is run, the normal things that happen when that event occurs are temporarily postponed while your function runs. If you don't stop the normal things from happening, they will happen when your function is finished. You may have several functions that depend on feedback from each other, and you can return values from your functions to indicate success or failure, or one state vs another. You can also return integers, strings, arrays, references to page elements..In this instance, returning false isn't necessary.

  10. IDs are not only used by CSS, so perhaps navcontainer is an id used by JavaScript to find the div. It's good practice to give major structures in your code an id because you will almost always wish to style them and it's the easiest way of selecting them.ul#navlist - means the unordered list with the id 'navlist'#navlist li - means all list items in the element with id 'navlist' (which we know to be an unordered list)The hash/pound sign (#) is used to select elements with a certain id, and the . syntax (for example, div.red) is used to select elements with a certain class. Classes can be used more than once on a page, but ids are unique. Note in the above examples that if ul#navlist had been written with a space - ul #navlist - the style would be applied to the element with id 'navlist' that is a child of any unordered list. I hope that helps.

  11. I sanitize user input by using PHP's htmlspecialchars() method and mysqli_real_escape_string(), stacked like so:$message = htmlspecialchars(mysqli_real_escape_string($conn, $_POST["message"]));When I display $message or fetch it from a database, tags appear as harmless symbols and text onscreen.You can try it here (it's ugly and clunky, but it was just a learning experience).

  12. There are a couple of browser specific ways of doing it. If you can be sure your users are going to be using Safari you can use the -webkit CSS properties, but you generally can't be sure of such things and your CSS won't validate. Until CSS3 is widely supported, you're best doing it with images. For image based rounded corners, check out cssplay.

×
×
  • Create New...