Hi,
I’m not very skilled at JavaScript, I just manage to use it when needed. I have a web page that gives me controls to remotely turn on or off a few items around the building, such as lights, ceiling fans and computers. The web page has no links to anything other than the server that hosts it, and there are no other pages. All links on the page send a string which is read by the server, and then a part of the server’s code is executed. Everything is functional, just not quite the way I want it.
I am trying to find a simple yet effective method of getting the web page to update after I click a button, say to turn on a light in a room. Right now, the web page is created based on inputs from a board controlling a set of relays, so if a particular relay is on, the page only gives me the option to turn off that relay. I’m not sure if you’d call this dynamic, but it’s at least conditional. When I click a button to turn on/off something, the page doesn’t update to show the change until the next time I click a button, or if I make the page auto-refresh. Due to the strings sent by the page, I don’t want to use a page refresh from the browser because it will resend the same string causing problems in some cases. I added a redirect which sort of serves the purpose by requesting the base page of http://server.ip/ with no added string, except that makes the browser constantly busy pulling the page every x seconds. But currently x is about the maximum time I’d like to wait after clicking a button before the page is updated.
I am thinking JavaScript should be able to do what I need, but I have not been able to get it to work. Either I may need to find a way to make the content="3; in the following
<meta http-equiv="refresh" content="3; url=http://server.ip/">
be variable based on just having clicked a button, perhaps redirect to http://server.ip/ in 1 second if I just clicked a button, and change to 200 seconds after that, or add some javascript functions that are called when a button is clicked, such as
<SCRIPT LANGUAGE="JavaScript">
var myURL='';
function myMultiLink(myURL) {
window.location.href='myURL'
window.location.href='http://server.ip/';
}
function url1() {
var myURL = 'http://server.ip/?device1on';
myMultiLink();
}
function url2() {
var myURL = 'http://server.ip/?device1off';
myMultiLink();
}
</script>
so that myURL is a variable set when a button is clicked. The functions might be called from the links on the page like this:
<a onclick="function url1()" href="javascript:void(0); return false">Fan On</a><br /><br /><br />
I want the function to assign the string such as /?device2on to myURL variable, then call myMultiLink() passing myURL to it and have that function request for example http://server.ip/?device2on (which doesn’t load a new page but only sends /?device2on to the server to carry out) and then the function request for the base page of http://server.ip/ to load which will refresh the contents showing the updated status (light is now on, so page should show option to turn it off).
The code above doesn’t work for me at all, as in nothing happens when I click the links. I am obviously doing something wrong, but I don’t know what/where it is. I own all the equipment involved, but am not able to implement any server-side scripting due to hardware/software limitations(at least as far as I know). I can make the server add components to the web page based on other factors as needed. Any suggestions/solutions are greatly appreciated!
Thanks,
Kent