Click to See Complete Forum and Search --> : could someone help me with this confirm script?


mitya
10-01-2003, 06:14 PM
Hi all

I have a call to a javascript inside a <span> tag, which, if the user clicks 'yes', I want the text to change colour. Please be quite specific if you can help as I'm no JS coder (just PHP/AS).

I know how to change properties on events etc, but what I want to know is how can I tell the text in the span to change colour only if yes is clicked in the confirm box?

To summarise:

1) Span tag, with text inside which, when clicked, calls confirm script

2) On confirm = yes, change script colour. If no, do nothing.

Thanks in advance- I hope this is possible.

pyro
10-01-2003, 06:22 PM
How about something like this:

<script type="text/javascript">
function changeColor(obj) {
change = confirm("Are you sure?");
if (change == true) {
obj.style.color = 'red';
}
}
</script>
</head>
<body>
<p><span onclick="changeColor(this);">test</span></p>

mitya
10-01-2003, 06:26 PM
Thanks for the second time in a day, Pyro- I'll give it a go!

:)

pyro
10-01-2003, 06:28 PM
Sure thing... :)

mitya
10-01-2003, 07:07 PM
Actually Pyro I couldn't get it to work :( I suppose the general basis of what I need to know is:

How do you change the properties of things in the <body> from within scripts in the head when the script is called? Surely I'd need to pass the span name to the script when calling it?

Thanks again.

pyro
10-01-2003, 08:56 PM
I am passing the <span> to the function:

<script type="text/javascript">
function changeColor(obj) {
change = confirm("Are you sure?");
if (change == true) {
obj.style.color = 'red';
}
}
</script>
</head>
<body>
<p><span onclick="changeColor(this);">test</span></p>

Anyway, if you explain a bit better what it is that you need to do, perhaps I could help you. Not sure what isn't working for you/what you want to be able to do.

mitya
10-02-2003, 07:11 AM
Got something to work in the end, Pyro- cheers anyway. The tricky part was the fact that I was mixing HTML, JS and PHP! The PHP was printing out the JS and so on... not an easy day.

:)