View Full Version : Generator Issues

08-26-2008, 01:08 AM
I am trying to make a link generator so far i have this...

function cod(url, txt, target) {
if (target==blank) {
var trgt="target=\"_blank\"";
else {
document.getElementById('code').innerHTML = "<a href=\"" + url + "\"" + trgt + ">;" +

txt + "</a>"
URL<input type="text" id="url"><br>Link Text<input type="text" id="txt"><br>New Window<input type="checkbox"

id="target" value="blank"><br><button onclick="cod(document.getElementById('url').value,

document.getElementById('txt').value, document.getElementById('target').value);">Go!

</button><br><textarea id="code"></textarea>

But nothing happens when the function is called does anyone know why?:confused:

08-26-2008, 04:49 AM
First, you miss to close your cod function.
This part is erroneous:

if (target==blank)

You need to surround it with quotes:

if (target=='blank')

But that does'nt makes sense. Since the checkbox value will always be "blank", not unless you explicitly change it. You must verify if the checkbox is checked instead:

if (document.getElementById('target').checked)

Use value in replace of innerHTML for textarea.
Your script logic is erroneous. If checkbox is checked, you'll assign to trgt variable the value target="_blank", otherwise print to the textarea the code.

You might find this modification useful:

function cod(url, txt, target) {
var trgt="";
if (document.getElementById('target').checked) trgt="target=\"_blank\"";
document.getElementById('code').value = "<a href=\"" + url + "\" " + trgt + ">" + txt + "</a>"

Hope it helps.