Email conversation
From | Marc B. |
To | Me |
Subject | Passing Document properties when self-submitting a form |
Date | 19 June 2003 01:34 |
Hi,
I read your article 'Transfer variables from the
location bar into JavaScript code' at
'http://www.howtocreate.co.uk/tutorials/jsexamples/vartransfer.html'.
It describes almost what I am trying to accomplish -
maybe you can point me in the right direction.
You describe how to pass variables that the _user_
gives a value. I want to pass a variable that
contains a value derived from a javascript function.
Like this:
<a href="projects.php?project=getProjectName()"> info
</a>
where 'getProjectName()' is a javascript function that
returns the value of a variable previously set.
Context:
I have a series of thumbnails on 'projects.php'. On
rollOver of each of them I set the image.src of a big
image so that user can select a project by mousing
over a thumbnail. Also on 'mouseOver' a function gets
called that stores the image.src of the big image in a
variable. When the link 'info' is clicked, I want the
value of image.src be added to the url, so that I can
return the appropriate text. In the example above I
only get the literal string ('getProjectName()') and
not the value I am looking for.
I hope I made myself clear.
thanks!
Marc
From | Me |
To | Marc B. |
Subject | Re: Passing Document properties when self-submitting a form |
Date | 19 June 2003 08:45 |
Marc,
There are a few of ways to accomplish what you want. The first way is to
hook the mouseover into a hidden input for a form, another is to dynamically
change the href of the link, and another is to use script in the href of the
link (I personally prefer this one). All these techniques require javascript,
as you are using javascript to set the src.
for your purposes, the third technique is the simplest:
<a href="javascript:window.open('projects.php?project='+getProjectName(),'_self');">Info</a>
(_self ensures it opens in the current window/frame)
but here are the other two techniqes, just in case you wanted them:-
1:
NOTE: you will have problems in Netscape 4, Escape and Omniweb 4.2- if the
form or link is in a layer (absolutely or relatively positioned div).
<form method="get" action="projects.php" name="uniquename">
<input type="hidden" name="project">
<input type="submit" value="Info">
or
<a href="javascript:document.uniquename.submit()">Info</a>
</form>
<a href="#" onmouseover="doThumbnailEffect('blah.jpg');">
<img src="thumbnail.jpg">
</a>
...
function doThumbnailEffect(theSRC) {
... do the image swap here ...
document.uniquename.project.value = theSRC;
}
2:
<a href="youNeedJavaScript.html">Info</a>
<a href="#" onmouseover="doThumbnailEffect('blah.jpg');">
<img src="thumbnail.jpg">
</a>
...
function doThumbnailEffect(theSRC) {
... do the image swap here ...
document.links[10].href = 'projects.php?project=' + theSRC;
//this assumes that you know the index of the link
}
hope this helps
Tarquin
From | Marc B. |
To | Me |
Subject | Re: Passing Document properties when self-submitting a form |
Date | 20 June 2003 14:15 |
Thanks!
It took me 3 days to figure this out :~ and I was
almost there but your tips tipped the balance. Some
JAvaScript quirks remain though - I cannot refer to
the hidden form field by name:
document.uniquename.project.value is not an object
according to IE but document.[0].project.value is
correct. ????
Thanks again,
Marc
From | Me |
To | Marc B. |
Subject | Re: Passing Document properties when self-submitting a form |
Date | 19 June 2003 08:45 |
Sorry, did I confuse you?
uniquename is the name I gave to the form containing the input
<form method="get" action="projects.php" name="uniquename">
you need to put that property in there or it won't work.
By the way, the form technique really is not the best. You would be better
off with:
<a href="javascript:window.open('projects.php?project='+getProjectName(),'_self');">Info</a>
keep the quotes in the right places, and it should just work as it is
Tarquin