Jump to content

Pollux

Members
  • Posts

    102
  • Joined

  • Last visited

Posts posted by Pollux

    syntax

    As boen_robot says, XML just stores data, it doesn't actually do anything. Maybe you're thinking of XHTML? Or some other application/technique that uses data held in XML format?If you give us a bit more background about what you're trying to do, we might be able to point you in the right direction.

  1. Absolute positioning should work fine, if you post your code someone can point out where you've gone wrong. The following code is from the w3schools pages:

    <style type="text/css">h2.pos_abs{position:absolute;left:100px;top:150px}</style>

    But, yours is for a table rather than a h2, so you'd need "table.pos_abs" instead. Then you need to make sure you've set the class for your table:

    <table class="pos_abs">

  2. Put the game play inside a function, and if you don't want that function to continue running then just return from the function, e.g.:

    function gameover(){    window.location="http://www.geocities.com/zelda_life/game_over.html";}function play(){    alert("It is dark night.");	    if (!confirm("Would you go to out?")){        alert("Huge boulder crashed your house,and you die.");        gameover();        return;    }	    alert("Outside is cold,but it feels good.");	    var nimi=prompt("What's your name?Asks stranger.","");    if (nimi!=null && nimi!=""){        alert("" + nimi + "...Interesting...");    }}

  3. It's worth noting that preventing the user from using the back button is one of the worst design decisions in almost all cases. Users resent being restricted from using the back button, and for less experienced users it is confusing. It's a usability issue that should be avoided in most cases.

  4. As Chocolate said, you've got a form element there with an id of "pw" which is inside the "login" form.

    <input name="pw" type="password" id="pw">

    The javascript is reading in the value of this field and appending it to the url, so the contents of this password field will be appearing on the querystring in plain text:

    ?page=level20&pw=PASSWORD

  5. The easiest way of doing this is just to insert "return" into your call to confirm():

    <a href="http://www.w3schools.com" onclick="return confirm('Do you really want to go here?');">LINK</a>

    If the message "Do you really want to go here?" is going to be the same for every link, then it will be slightly preferable to use your own function that you can call without any parameters and which will call the confirm. Doing it this way avoids duplication of the text and leaves you with only one place to change it if you decide to reword it:

    function confirmLink(){  return (confirm("Do you really want to go here?"))}

    and the link:

    <a href="http://www.w3schools.com" onclick="return confirmLink();">LINK</a>

  6. Theres quite a few little things you can improve in your code. - Theres alot of shortcuts in javascript you could do with using, e.g. player_HP -= 10; IS THE SAME AS player_HP = player_HP - 10; power++; IS THE SAME AS power = power + 1;- As well as setTimeout(), there is also a setInterval() function, which is more suitable for what you are doing here. This was part of the problem with your function not stopping. setInterval calls a function every x ms.- Instead of doing (enemyHP == 0 || enemy < 0) you can just use (enemy <= 0), "less than or equal to"I fixed up your code a little, so you can see it below. You'll also notice I fixed a few other little problems and theres still some that could be improved, I'll leave it up to you to find them.

    <html><head><script>var player_HP=100;var power=0;var enemyHP=100;var enemyTime;function startGame(){	enemyTime = setInterval("enemyattack()",5000);}/*****************************ENEMY ATTACK********************************/function enemyattack(){	if (enemyHP<=0){  alert("You win!");  clearInterval(enemyTime)	}else{	  var enemyattack = Math.floor(Math.random()*10);  if (enemyattack<5 && enemyattack>1){  	player_HP -= 10;  	document.getElementById('player_HP').value=player_HP;  }else{  	player_HP -= 20;  	document.getElementById('player_HP').value=player_HP;  }    if (player_HP < 1){  	window.location="http://www.google.com"  }	}}/******************************PLAYER ATTACK***************************/function attack(){	enemyHP -= power;		document.getElementById('attack').value=enemyHP;		power = 0;	document.getElementById('powerlevel').value=power;}function powerup(){	power++;	document.getElementById('powerlevel').value=power;}</script><body>	<input type="button" value="Start!" onclick="startGame()" />		<p>HP <input type="text" value="100" id="player_HP" /></p>		<p>Enemy HP <input type="text" value="100" id="attack" /></p>		<p>Power level <input type="text" value="0" id="powerlevel" /></p>		<input type="button" value="Attack!" onclick="attack()" />		<input type="button" value="Raise power" onclick="powerup()" /></body></html>

  7. Strangely, your code seems to be working fine for me in both IE and Firefox. There are a couple of errors (such as closing the style and script tags: <style type="text/css" /> before their contents, you need to remove the slashes) also the javascript function should be in the head really. But these things apparently aren't stopping it working for me. Just to make sure I completely understand what you're seeing: after pressing all the radio buttons one at a time you end up with question 1), questions 2) -> 3) and questions 4) -> 12) ALL showing at once?You import an external javascript "utility.txt" (which should be named .js really btw). What's in this file?

  8. I may be wrong, but I don't think there is any way of doing that. Although, even if you can I'm not sure it would be a good idea. If two styles are always going to have an attribute that is the same, pull the common attributes into a new style since logically they're independent and then in all the places you want that color attribute you use both styles.That also achieves your aim of only one place to update.Hope that helps!

  9. I think there must be a problem else where in your code because this is working fine for me now. It could be some of your styles are conflicting. Can you post the rest of the html document? Particularly the "both" and "neither" divs.We'll get it eventually!

  10. At the bottom of each page of this forum there is a white bar which contains a link to a lo-fi version of the forum and also a date/time string. Unfortunately both of these are also white, making them effectively invisible.Some users may find a lo-fi version of the forum useful but are unaware the link exists. I suspect the effect of this colouring has just been overlooked, and will be easy to fix, so I thought it should be brought to the attention of the admins.

  11. ah, I see! Ok, well theres a couple of things I'd recommend you change first. You only need to send the element id in the call to onchangeQu1, then get the actual object reference by calling getElementById in the function. That will simplify your function calls some what.Also, your html contains a <h3></h3> inside a table but outside a cell which isn't valid, so you probably meant to put a new row with one cell in there.The simplest way of only displaying the correct div is to keep an array of all of them outside the function. It could be done in a neater way, but this is probably the easiest and simplest way of doing it. Heres the updated script:

    var qu1Div = new Array(2);qu1[0] = "both";qu1[1] = "neither";function onchangeQu1(theRadio, theObjectId){    theObject = document.getElementById(theObjectId);	    if(theRadio.checked){        // Remove all.        for(i=0; i<qu1.length; i++){            document.getElementById(qu1[i]).style.display = "none";        }        // Display the correct one.        theObject.style.display='block';    }else{        theObject.style.display='none';    }}

  12. Just give it a style, you'll need to use both color and background-color to make it work on both IE and Firefox, and you should also set a border size of 0, otherwise it doesn't seem to take effect on Firefox:

    <hr style="border: 0; color: #FF0000; background-color: #FF0000;" />

  13. Glad you've made progress! It sounds like you've implemented it the way I described, so I'll explain for that, but if you based it somehow upon vijay's response, then this won't be all that helpful, and I'll just go off and crawl under a rock. :) All you need to do is as well as setting the style for the newly selected radio button's new question, you also need to set the display style for all the other alternatives which weren't selected to "none", so they don't display. If you post the code you've come up with so far then it will be easier to see and explain the best way to go about this.

  14. Your code does work, you are adding the two variables together. The problem is, you're not assigning the result to anything, so it effectively just disappears. If you want to update the number2 variable then you need to do that explicitly like this:

    number2 = number1 + number2;

×
×
  • Create New...