Click to See Complete Forum and Search --> : Newb script help needed


techietim
12-01-2003, 03:31 PM
I'm pretty new to javascript at the mo, and alot of the time I'm copy/pasting scripts over that I can use.

I'm currently writing an automatic record writer that I can use at work to make my life easier.

here's my work so far...
http://homepage.ntlworld.com/techie.tim/scripty1.html

Underneath the text box down the left hand side, I've written some signatures that can be added at the end of the record, however, what I really need is a way to store a single signature as a cookie, that can then be added on the end when pressing a button.

This will allow more people at my workplace to use the site, and not bog it down with too many buttons.

pleeze help me somebody???

96turnerri
12-01-2003, 06:24 PM
what you trying to do, looks like the signature thing is working atm or do you want it to automaticcally add signature by a cookie?, buttons could do with tidying up lol (thats sjust what id do)

techietim
12-02-2003, 02:04 AM
Yeah! Don't worry, I have plans for the buttons.

The Signature buttons I have at the moment are there only temporarily. I basically want it so others can use the page without me having to do a new button for them each time.

The best way I can think of doing this is by allowing people to create thier sig by a cookie, and then having a single button that would add it to the bottom of the list.

96turnerri
12-02-2003, 11:57 AM
what about a button and on click opens a prompet

Please Enter Your Name
.................
Ok Cancel

??

techietim
12-02-2003, 12:13 PM
That's ideal if it's going to set a cookie. but pointless otherwise, as I can just add the name manually at the bottom of the text area.

96turnerri
12-02-2003, 12:24 PM
<script type="text/javascript">

cookie_name = "dataCookie";
var YouEntered;

function putCookie() {

if(document.cookie != document.cookie)
{index = document.cookie.indexOf(cookie_name);}
else
{ index = -1;}

if (index == -1)
{
YouEntered=document.cf.cfd.value;
document.cookie=cookie_name+"="+YouEntered+"; expires=Monday, 04-Apr-2010 05:00:00 GMT";
}

}
</script>

<form name="cf">

Enter Your Name: <input type="text" name="cfd" size="10">
<input type="button" Value="Set to Cookie"
onClick="putCookie()">

</form>

<script type="text/javascript">

cookie_name = "dataCookie";
var YouWrote;

function getName() {
if(document.cookie)
{
index = document.cookie.indexOf(cookie_name);
if (index != -1)
{
namestart = (document.cookie.indexOf("=", index) + 1);
nameend = document.cookie.indexOf(";", index);
if (nameend == -1) {nameend = document.cookie.length;}
YouWrote = document.cookie.substring(namestart, nameend);
return YouWrote;
}
}
}
YouWrote=getName();

if (YouWrote == "dataCookie")
{YouWrote = "Nothing_Entered"}

</script>

<script type="text/javascript">
document.write("<textarea rows=10 cols=10 name=yourForm>"+YouWrote+"</textarea>")
</script>

techietim
12-02-2003, 01:20 PM
I'm having problems with this code.

I'm guessing that it's created the cookie ok, but how would I transfer it over to the text page, there's no button for that.

Also keep in mind that it needs to be added to the bottom of any text already in the field, and not replace it.

I haven't uploaded the page in case you're wondering.

96turnerri
12-02-2003, 02:48 PM
dont worry about uploading it, i will go to your site and get source and add in what i got and then give it to you, should be done arround, 10pm GMT (aprx 1h15m), gotta go out in a min so do it when get back

96

techietim
12-02-2003, 02:54 PM
Thanks, you're a gem!

I'm trying hard to learn javascript, but my brain just cant get round some concepts!

96turnerri
12-02-2003, 04:44 PM
here i done the cookie bit just need to get it to write into yourForm textarea

96 let me know if ok

techietim
12-02-2003, 04:57 PM
Looking good, however...

It came up showing "tim" in the box (which is from some previous cookie fiddle I guess). I changed it to my signature, clicked the button, and it held whenever I hit the refresh key.

But when I clicked on "clear", it reverted back to "tim"

oh hang on, I see whats happening.

The cookie isn't accepting spaces in the signature. Is there any way round that?

96turnerri
12-02-2003, 05:03 PM
i cannot see why not accepting two words, tried it on mine doesa the same, going to bed now, look at it for you in morning? not desperate for it are you?

techietim
12-02-2003, 05:09 PM
No, not absolutely despirate.

I've been working on this thing for ages, and I really appreciate the help you're giving me.

I'm completely in your hands.