Jump to content

mike_g

Members
  • Posts

    48
  • Joined

  • Last visited

Previous Fields

  • Languages
    Java, Javascript, PHP

Contact Methods

  • Website URL
    http://
  • ICQ
    0

mike_g's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. Oh yeah... I forgot about that. Bit of a dumb error really, but thanks for the help.
  2. I havent tested this but I imagine this should work: var max_x = 1024var cup = document.getElementById("cup")var cup_x = 0var inc = 10function moveWin(){cup_x = cup_x + inccup.style.left = cup_x + 'px' if (cup_x >= max_x || cup_x <=0) inc = -inc timerID = setTimeout("moveWin()", 25) } Instead of moving the cup +10 each time the function is run we now have a variable to increment it by. If it goes above the page width or below 0 then the increment gets inverted causing the window to move in the opposite direction.
  3. I want to draw an image in a Javascript function. I can't seem to get it to work. Heres an example of what I am doing: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html><head><title>Untitled</title><script language="JavaScript" type="text/javascript">function DrawRow(img){ document.write("<img src='"+img+"' alt='not working' />");}</script></head><body><img src="Images\Rompersuit.jpg" /><script>DrawRow("Images\Rompersuit.jpg")</script></body></html> Can someone please tell me how I could get this to work. Thanks.
  4. I want to change the selected radio box in a form using javascript. I couldent seem to find any examples in the W3 tutorials and I havent been able to work it out for myself yet. Below is an example prog I made. The Change() function is my best guess at what would work, but it dosent. Can someone tell me how to do this right? Cheers. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><title>Page title</title><script>function Change(){ document.c_form.nclass.value = "A";}</script></head><body onload="Change()"> <form name="c_form"> A<input type="radio" name="nclass" value="A"> B<input type="radio" name="nclass" value="B"> C<input type="radio" name="nclass" value="C"> D<input type="radio" name="nclass" value="D"> </form></body></html>
  5. Heres a little binary maths game I made in javascript. Hope you guys like it
  6. mike_g

    About quotes

    I got it sorted now so now need for help any more.
  7. mike_g

    About quotes

    I made a little game in javascript using checkboxes. Checkboxes are small and fiddly so I want to replace them with images. I'm having a problem at the moment with quite a large string. My prog is a bit big to post but here is the function I'm having probs with: function DrawBit(state, bit){ var str = "b"+bit; if (state == 0) { state[bit]=1; UpdateText("'b"+bit+"'", "<img src='On.PNG' onclick='UpdateText("+str+", DrawBit(1, "+bit+"))' />"); } else { state[bit]=0; UpdateText("'b"+bit+"'", "<img src='Off.PNG' onclick='UpdateText(" +str+ ", DrawBit(0, "+bit+"))' />"); }} Basically when the image is clicked I want to change its state and picture. My problem is where you see the: +str+It seems that here I would need a third seperate set of qoutes on top of the ' and " symbols. Do these things exist? Or does anyone know how I could get this to work, thats if its possible to get it to work. Oh yeah and just in case it helps heres the UpdateText() function: function UpdateText(area, change_to){ document.getElementById(area).innerHTML = change_to;} And heres one of the original lines that gets wrote in the HTML file: document.write("<td><div id='b0'><img src='Off.PNG' onclick='UpdateText(", '"b0"', " , DrawBit(1, 0))' /></div></td>");
  8. Thanks for the help, works fine now
  9. Hi! I'm kinda new to javascript and i'm trying to make a little prog that lets you add stuff to a shopping cart. Its done using a form with checkboxes. Now what I got works but sometimes the output in the total box is wrong. Usually after selecting, and deselecting several items. EG: selecting rompersuit and deodorant, then delselecting them both results in a total of -1.776356. The numbers it comes up with are weird and I've got no idea where they come from o_O Heres my code: <html><head><script language="JavaScript" type="text/javascript">function ADD(name,cost){ var sum = eval(document.ShopForm.total.value); if (name == true) sum = sum + cost; else sum = sum - cost; document.ShopForm.total.value=sum; }</script><title>Untitled</title></head><body><form name="ShopForm"> <table> <tr> <td>Helmet</td> <td>$27.50</td> <td><input type='checkbox' name='helmet' onchange='ADD(document.ShopForm.helmet.checked, 27.50)'/></td> </tr> <tr> <td>Guinea pig</td> <td>$24.00</td> <td><input type='checkbox' name='guineapig' onchange='ADD(document.ShopForm.guineapig.checked, 24.00)'/></td> </tr> <tr> <td>Trike</td> <td>$135.95</td> <td><input type='checkbox' name='trike' onchange='ADD(document.ShopForm.trike.checked, 135.95)'/></td> </tr> <tr> <td>Hacksaw</td> <td>$12.50</td> <td><input type='checkbox' name='hacksaw' onchange='ADD(document.ShopForm.hacksaw.checked, 12.50)'/></td> </tr> <tr> <td>Rompersuit</td> <td>$29.99</td> <td><input type='checkbox' name='rompersuit' onchange='ADD(document.ShopForm.rompersuit.checked, 29.99)'/></td> </tr> <tr> <td>Deodorant</td> <td>$3.99</td> <td><input type='checkbox' name='deodorant' onchange='ADD(document.ShopForm.deodorant.checked, 3.99)'/></td> </tr> <tr> <td>Total</td> <td><input size=6 name='total' value='0'></td> </tr> </table></form></body></html> Anyone know whats going wrong? Cheers.
×
×
  • Create New...