Click to See Complete Forum and Search --> : problems with functions


David Harrison
04-13-2003, 02:51 PM
I want to write a function that will creat a link for me, it's so hard to explain but here I go.

I'll put the funtion in a separate .js file and in the main page I'll have something like this (I'm not entirely sure how to get a function to work on the page so I'll just guess):

<script language="javascript">
link(hi there)
</script>

and the link written would be

<a href="hi there.html">hi there</a>

Can anyone help me (tell me) what the function in the .js file should be and how I could "activate" the function on the page please?

AdamGundry
04-13-2003, 03:34 PM
Function in the JS file:

function link(targ){
document.write('<a href="' + targ + '.html">' + targ + '</a>');
}


Activating on a page:

<script type="text/javascript">
link('Hi');
</script>


What do you need to use this for? If it's just for speeding up coding, remember this will fail in 1 in 10 browsers.

Adam

David Harrison
04-13-2003, 04:25 PM
Thanks for the code, it's not just for speeding up coding, it's also because I'm sort of trying to cram in as much js into my site as possible (the one in my signature).

AdamGundry
04-13-2003, 04:30 PM
Why do you want to use so much JS? It'll only make your site unsuable for 1 in 10 surfers, and your page doesn't need it.

By the way, you can't copyright the name (in the UK, and I presume in the US) - copyright is for original works, for names and titles you have to get a trademark.

Adam

David Harrison
04-15-2003, 12:09 PM
I didn't know that, presumably not many other people know that, so as long as everybody doesn't find out I guess I'm OK.
Also, I really don't care if people take the name because I just thought it would look professional when I wrote it.