||09-29-2012 08:48 AM
Making an AJAX announcement
I want to know how to write a bit of script that will allow me to post a announcement on the top of a page with a form, so that it changes for everyone.
//this is my form
<input type='text' id='userInput1' />
<input type='button' onclick='announcement()' value='Set Announcement' size='30'>
var userInput = document.getElementById('userInput1').value;
document.getElementById('boldStuff1').innerHTML = userInput;
So what it dose is, when you type something into the input box and hit submit, it changes the announcement for everybody. How can i do this?
||09-29-2012 01:28 PM
||09-29-2012 04:12 PM
You do not need ajax for this. here is a method using php.
$do = 'yes';
$ann = '';
$file = @fopen("announcement.txt","r") or exit("announcement file does not exist!");
$ann .= fgets($file);
if($ann != '') $ann = $ann.'<br />';
if($ann == '')
$do = 'no';
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
border: black solid 1px;
$mystring = <<<EOT
if($do == 'yes') echo $mystring;
Give me an announcement
The text file "announcement.txt" is your announcement and looks like this:
Now is the time
for all good men
to come to the aid
of their country
Test this with the given text file. Then empty the text file of everything and lastly test it by deleting the file altogether.
If you like this approach and want further explanation of the code just LMK.
||09-30-2012 03:02 AM
Thanks for that, it works. Now, what i wanted to do is, when i type into a input box say, Test, and then hit the button, it will set the announcement.
How will i do this?
||09-30-2012 04:49 PM
When the button is hit you take what is written in the textarea and overwrite a text file called announcement.txt with it. This should be easy to do so I'm not coding it. If you have trouble with it post the code you have and we'll correct it.
|All times are GMT +1. The time now is 02:24 AM.
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.