Click to See Complete Forum and Search --> : doing <A DREF> within JS function


VileFriend
08-14-2003, 09:42 AM
I must be dumb or something but how do I link a page with JavaScript so that I can put that it into a conditional loop on a page?
:o
function inform()
{
alert("You answered NO! so I will href it");
}

function inform2()
{
alert("You answered Yes so now I Loop!");
}

function inform3()
{
should be <A HREF "C:\_My Documents\RichkaVCA\While\Have you received your letter from the queen.htm" <A>
if done in HTML (or would it?)
}

My ignorance would appreciate your help, thanks.

AdamGundry
08-14-2003, 10:10 AM
I'm not sure if I understand you properly - do you want to use Javascript to move to another page? If so, you can use this:

location.replace('http://www.example.com');

If not, please explain more clearly.

Adam

VileFriend
08-14-2003, 06:00 PM
Thanks Adam. Please visit this page.
Javascript linking #2 (http://homepages.paradise.net.nz/richka/files/VCA-While002.html):D It's hard when I have no books to reference! Being without credit card or ability to get one doesn't help either:mad:

VileFriend
08-14-2003, 07:01 PM
This guy (me) needs to visually spellcheck!:(
not doing <A DREF> within JS function but
doing <A HREF> within JS function

AdamGundry
08-15-2003, 02:41 AM
I don't see what needs to be done to the page now - the code is working, unless there is something else you want it to do. By the way, you might want to use this instead of location.replace():

location.href = thelink;

Adam

P.S. There's a handy JS reference (http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/) at Netscape Devedge (http://devedge.netscape.com/).

VileFriend
08-15-2003, 05:21 AM
Thanks again AdamGundry, is location.href better?
About the only thing I have to resolve now is the best way to redraw the page with the altered question! It's weird how you can embed JS to html but not vice versa eh. I'm thinking of utilising popup windows, what do you reckon? By the way, I do know about Netscape Devedge but did you know about
Lycos webmonkey tutorials (http://hotwired.lycos.com/webmonkey/programming/javascript/tutorials/jstutorial_index.html)
Shame my [img] is turned off and I don't know how to turn it on otherwise: http://homepages.paradise.net.nz/richka/gifs/ThankYou/thankyou blue sparkly.gif

AdamGundry
08-15-2003, 11:40 AM
Thanks. :D

You can generate HTML from JS with two methods:

1. Use document.write('<h1>Some <em>HTML</em></h1>'); - this only works when the page is first loading.

2. Use innerHTML, like this:
<div id="question"></div>
<script type="text/javascript">
document.getElementById('question').innerHTML = '<h1>Some <em>HTML</em></h1>';
</script>

Adam

VileFriend
08-16-2003, 04:06 AM
Interesting Adam but as I said right at the beginning, I must be dumb! I don't really understand your code :confused: probably because I don't really understand JS or HTML! So far so good tho' but how do I make a local file be recognised as a url? A url starts http://... and when I try to location.replac(""); with a local file it says file not found!? Also, am I on the right tract doing it with popup windows for each question? Variable transferred via document.cookie() I imagine. tHE VARIABLE STORED IN ram AND ACCESSED VIA THAT INBUILT FUNCTION? whoops damn caps lock! Here's another that you undoubtedly already know of, if you're interested The JavaScript Source Master List (http://javascript.internet.com/master-list/):)

AdamGundry
08-16-2003, 05:33 AM
As far as I am aware (see the Location object documentation (http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/location.html)) you can specify a local file, as long as you use the file: protocol, or a relative path (i.e. not specifying the protocol). So all these should work:

location.replace('http://www.example.com');
location.replace('example.html');
location.replace('file:///C:/example.html');

I would advise against using popup windows if possible - you can transfer values using document.cookie between pages in the main window.

Adam

P.S. I found this JS tutorial useful: http://www.javascriptmall.com/learn/contents.htm

VileFriend
08-16-2003, 07:24 AM
:D Yeah thanks Adam :///C:/example.html is all I really needed. I wasn't sure but now it is confirmed for me that preceeding the local absolute address with 3 /// is what replaces the //http! So it looks like http = /!
Okay, granted using multiple windows is bad but how else should/could I redraw that page(window) with the changed variable data? Also, where HTML takes a string as an argument like bgcolor="#D8AFDA" how do I make it take the JS variable?:eek: I guess I document.write(variable) don't I?
;)
I do have that tutorial bookmarked also as I do so many others like Doc JavaScript - JavaScript Tip of the Day Archive (http://webreference.com/js/tips/browse.html?cat=ib&start=11&page=10&hide=0&order=0)
HTML is so weird man! It doesn't seem logical in how it does the lines of code! What comes after some things does not necessarily appear that way, Especially hard without a validator. You got one? I've found that unless the tags are closed HTML swallows the lines! :mad:
Nevermind, slowly slowly catchee monkey:confused: ;) Cheers for your help so far mate.

AdamGundry
08-16-2003, 07:42 AM
If you create a <div> tag with an ID, like this:
<div id="question"></div>

You can then change its contents using the Javascript property innerHTML - use document.getElementById() to refer to the element, as shown here:
<script type="text/javascript">
var someHTML = '<h1>Some <em>HTML</em></h1>';
document.getElementById('question').innerHTML = someHTML;
</script>

A useful online validator for HTML (and other markup languages) is available at http://validator.w3.org/.

Adam

VileFriend
08-16-2003, 08:13 AM
<em> = emphasis ehich means :confused: Oh, I see we can write code into ours posts, thats good. Boy you're quick to respond, that's also good. It's 1am on Sunday here what time you got?
That validator is online but for quicker reference try this attached one?:p

VileFriend
08-16-2003, 08:30 AM
<em> = emphasis ehich means :confused: Oh, I see we can write code into ours posts, thats good. Boy you're quick to respond, that's also good. It's 1:10am on Sunday here what time you got?
That validator is online but for quicker reference try this attached one?:p

VileFriend
08-16-2003, 08:32 AM
<em> = emphasis ehich means :confused: Oh, I see we can write code into ours posts, thats good. Boy you're quick to respond, that's also good. It's 1:30am on Sunday here what time you got?
That validator is online but for quicker reference try the one you gdownload here CSE HTML Validator (http://www.htmlvalidator.com/)

AdamGundry
08-16-2003, 08:53 AM
Emphasis (<em>) renders in most browsers as italic, but also has meaning for nonvisual browsers, so is more accessible: http://www.helical-library.net/desk/hg_em.html

Adam

VileFriend
08-16-2003, 09:17 AM
Wow Adam, I'm downloading this JavaScript Tutorial (http://vhttp://www.w3schools.com/js/default.asp) 3 pages deep! That's at my rural speed of 31.2kbps! Hope it's good. Do you know how I can add my own GUISmillies?
Yours is cool, so do you think yours is bigger than mine? I'll look later. Cheers:D:confused: :cool:

VileFriend
08-21-2003, 07:00 AM
AdamGundry sorry for the delay in reply but thought you might be interested in these. :cool:
HTML Tutorial (http://www.w3schools.com/html/default.asp) and JavaScript Tutorial (hhttp://www.w3schools.com/js/default.asp)
Ha! I'm using up too much net time but I made them available off-line so see ya later.:D

VileFriend
08-21-2003, 10:37 AM
Whoops, sorry AdamGundry I must have just previewed it and got distracted! However here are a couple of links to tutorials HTML Tutorial (http://www.w3schools.com/html/default.asp) and JavaScript Tutorial (http://www.w3schools.com/js/default.asp). I hope they're useful to yiou. I've made them available off-line cause I've used far too much net time as it is! I'll see ya later.