[thelist] changing link text on-the-fly with JavaScript

Chris Marsh chris at ecleanuk.com
Fri Mar 7 09:35:01 CST 2003


Sarah

> I have a page with a rather complicated form. Part of this
> form can be "saved" (really it will just be  hidden, using
> the CSS "display: none;") separately from the rest. What I'd
> like is for the value of the text box and file upload field
> in this part of the form to be used to change a link. So if
> the link is like this at first...
>    <a href="somefile.doc">original text</a>
> ...then the user enters "new text" into the text box, selects
> a file in the file upload field, and "saves" that section of
> the form, the link should say...
>    <a href="newfile.doc">new text</a>
> (Well, I guess the link would probably have to point to their
> local file at this point...)

CAUTION: I haven't invested too many cycles in this, so it's a starting
point only.

Assign your original link to a variable thus:

var link = 'somefile.doc';

Now your anchor should read <a href='javascript:document.location =
link'>.

Now, when the new file is selected insert a line of code changing var
link to the new value. After this, every time the link is clicked on the
new file is the target.

> If anyone knows how to do this using JavaScript
> (client-side), I'd really appreciate some hints to point me
> in the right direction. Otherwise I guess I can do this
> server-side - it would just be nice to be able to do it with
> client-side.

Regards

Chris Marsh




More information about the thelist mailing list