Jump to content

Jquery/Javascript help needed

Go to solution Solved by lubblig,

haha, I used some code from another site and thought it had to be the $function thing. But I tried to set it to "function NAMEHERE() {" and that worked. Thanks though!

I've got this script that I want to update automatically (it's a clock and I need it to update by itself to show the time correctly) without the need of a page refresh.

 

I've got this but I don't know how to do it, I cannot get setTimeout() to work because the function doesn't have a name (I think that's the reason)?

<script type="text/javascript">
$(function(){
  //code
  //not important to problem
  })
var t = setTimeout(function(),500);
</script>

The setTimeout part isn't working and I think it's because I'm not using it correctly or it just doesn't work in jquery. So I need help with code that can update it.

Spoiler

System:

i5 3570k @ 4.4 GHz, MSI Z77A-G43, Dominator Platinum 1600MHz 16GB (2x8GB), EVGA GTX 980ti 6GB, CM HAF XM, Samsung 850 Pro 256GB + Some WD Red HDD, Corsair RM850 80+ Gold, Asus Xonar Essence STX, Windows 10 Pro 64bit

PCPP:

http://pcpartpicker.com/p/znZqcf

 

Link to comment
https://linustechtips.com/topic/547224-jqueryjavascript-help-needed/
Share on other sites

Link to post
Share on other sites

I think you want setInterval rather than setTimeout. Timeout runs after a specified time then breaks, whereas interval keeps running. It's the same syntax as setTimeout

I am good at computer

Spoiler

Motherboard: Gigabyte G1 sniper 3 | CPU: Intel 3770k @5.1Ghz | RAM: 32Gb G.Skill Ripjaws X @1600Mhz | Graphics card: EVGA 980 Ti SC | HDD: Seagate barracuda 3298534883327.74B + Samsung OEM 5400rpm drive + Seatgate barracude 2TB | PSU: Cougar CMX 1200w | CPU cooler: Custom loop

Link to post
Share on other sites

5 minutes ago, Hazy125 said:

I think you want setInterval rather than setTimeout. Timeout runs after a specified time then breaks, whereas interval keeps running. It's the same syntax as setTimeout

No, that doesn't work either. I think that the problem is that my function is called "$(function() {" and the setTimout/setInterval cannot do anything with it because it doesn't have a name.

Spoiler

System:

i5 3570k @ 4.4 GHz, MSI Z77A-G43, Dominator Platinum 1600MHz 16GB (2x8GB), EVGA GTX 980ti 6GB, CM HAF XM, Samsung 850 Pro 256GB + Some WD Red HDD, Corsair RM850 80+ Gold, Asus Xonar Essence STX, Windows 10 Pro 64bit

PCPP:

http://pcpartpicker.com/p/znZqcf

 

Link to post
Share on other sites

haha, I used some code from another site and thought it had to be the $function thing. But I tried to set it to "function NAMEHERE() {" and that worked. Thanks though!

Spoiler

System:

i5 3570k @ 4.4 GHz, MSI Z77A-G43, Dominator Platinum 1600MHz 16GB (2x8GB), EVGA GTX 980ti 6GB, CM HAF XM, Samsung 850 Pro 256GB + Some WD Red HDD, Corsair RM850 80+ Gold, Asus Xonar Essence STX, Windows 10 Pro 64bit

PCPP:

http://pcpartpicker.com/p/znZqcf

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×