Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Links?

Status
Not open for further replies.

danomaniac

Programmer
Jan 16, 2002
266
US
Hello - I'm a vba guy, don't know javascript very well so I need some help. I have a simple page with a table that has three columns. Each cell in the right column has a hyperlink. I want to be able to type a url in a text box, hit submit, and the script would then add a row to the table, create a hyperlink with the url from the text box, insert it in the right cell of the new row, then save and refresh the page. Thanks in advance for any help.

"It's more like it is now, than it ever has been."
 
Hi

Nice plan, however sounds pointless. Why to update the document with JavaScript right before refreshing it ? Just submit the [tt]form[/tt], handle the data server-side, then generate the new document.

Feherke.
 
Because I don't have a server. This is just a simple html page that I am using for my active desktop with links to documents on my computer instead of shortcuts (icons).

"It's more like it is now, than it ever has been."
 
Hi

danomaniac said:
I don't have a server
I supposed "save" means writing it in a database.

Your requirement sounds abit like TiddlyWiki. I would take a look at it to see how they solved the saving. That would be the most complicated part of your requirement.

As an alternative to skip the saving, you could store the URLs in cookies, however the cookies are limited in size and amount. HTML 5 introduced DOM storage, which you could use similarly to storing in cookies, but much easier and safer. But it requires Explorer 8.

Feherke.
 
If you're using Active Desktop then my guess is the "page" will run in the context of IE, so you should be able to use the FileSystemObject ActiveX control to load & save files locally on your computer.

Check out my (admittedly now very old) FAQ here for a quick demo on how you might read & write to a text file:

faq216-5305

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
Thanks everyone for your help. I've realized this is far too difficult for such a simple application. I merely like links on my desktop more than icons, so I thought it would be nice to be able to add them dynamically - I guess I'll just continue to edit the html and add the links that way.

Thanks again.

"It's more like it is now, than it ever has been."
 
Hi

If you have Explorer 8, and active desktop uses the same rendering engine (*), it is very simple.

(*) You can find it out by putting this code in an HTML document and set it as active desktop. If it displays "object", it handles DOM storage. If it displays "undefined", no luck.
JavaScript:
document[teal].[/teal][COLOR=darkgoldenrod]writeln[/color][teal]([/teal][b]typeof[/b] window[teal].[/teal]localStorage[teal])[/teal]


Feherke.
 
Hi

Just to prove how simple is using DOM storage :
HTML:
[red]<!DOCTYPE[/red] [maroon]HTML[/maroon] [maroon]PUBLIC[/maroon] [green][i]"-//W3C//DTD HTML 4.01//EN"[/i][/green] [green][i]"[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd"[/URL][/i][/green][red]>[/red]
[b]<html[/b] [maroon]lang[/maroon][teal]=[/teal][green][i]"en"[/i][/green][b]>[/b]

[b]<head>[/b]
[b]<meta[/b] [maroon]http-equiv[/maroon][teal]=[/teal][green][i]"Content-Type"[/i][/green] [maroon]content[/maroon][teal]=[/teal][green][i]"text/html; charset=iso-8859-1"[/i][/green][b]>[/b]
[b]<title>[/b]2 c[b]</title>[/b]
[b]<style[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"text/css"[/i][/green][b]>[/b]
table,tr,th,td { border: solid silver 1px }
[b]</style>[/b]
[b]<script[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"text/javascript"[/i][/green][b]>[/b]

function load()
{
  for (var i=0,l=localStorage.length;i<l;i++) {
    var row=list.insertRow(-1)
    var cell=row.insertCell(-1)
    cell.innerHTML=localStorage.getItem(localStorage.key(i)).link(localStorage.key(i))
  }
}

function add()
{
  if (!url.value) return
  localStorage.setItem(url.value,text.value||url.value)
}

var url,text,list

window.onload=function() {
  url=document.getElementById('url')
  text=document.getElementById('text')
  list=document.getElementById('list')
  load()
}

[b]</script>[/b]
[b]</head>[/b]

[b]<body>[/b]

[b]<form[/b] [maroon]action[/maroon][teal]=[/teal][green][i]""[/i][/green] [maroon]onsubmit[/maroon][teal]=[/teal][green][i]"add(); location.reload()"[/i][/green][b]>[/b]
[b]<p>[/b]
[b]<label>[/b]URL[b]<input[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"text"[/i][/green] [maroon]id[/maroon][teal]=[/teal][green][i]"url"[/i][/green][b]></label>[/b]
[b]<label>[/b]Text[b]<input[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"text"[/i][/green] [maroon]id[/maroon][teal]=[/teal][green][i]"text"[/i][/green][b]></label>[/b]
[b]<input[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"submit"[/i][/green] [maroon]value[/maroon][teal]=[/teal][green][i]"Add"[/i][/green][b]>[/b]
[b]</p>[/b]
[b]</form>[/b]

[b]<table[/b] [maroon]id[/maroon][teal]=[/teal][green][i]"list"[/i][/green][b]>[/b]
[b]<tr><th>[/b]URL[b]</th></tr>[/b]
[b]</table>[/b]

[b]</body>[/b]

[b]</html>[/b]
Works in Gecko and WebKit. Failed in Presto and KHTML.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top