Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Adding JS variable to document.anchors["myLink"].href - is it possible?

Reply
Thread Tools

Adding JS variable to document.anchors["myLink"].href - is it possible?

 
 
Phil Powell
Guest
Posts: n/a
 
      04-27-2004
<script type="text/javascript">
function addFieldsToLink(link) {
var qs = ''; // QUERY STRING ADDITION
var val = '' // VALUE OF FORM ELEMENT;
for (i = 0; i < document.imageSearchForm.elements.length; i++) {
if (document.imageSearchFrom.elements[i].type == 'select-one') {
val = document.imageSearchForm.elements[i].options[document.imageSearchForm.elements[i].selectedIndex].value;
} else if (document.imageSearchForm.elements[i].type ==
'select-multiple') {
// DO NOT SET val HERE BUT ADD TO QS DIRECTLY
for (j = 0; j < document.imageSearchForm.elements[i].options.length;
j++) {
qs += '&' + escape(document.imageSearchForm.elements[i].name) +
'=' +
escape(document.imageSearchForm.elements[i].options[document.imageSearchForm.elements[i].selectedIndex].value);
}
} else if (document.imageSearchForm.elements[i].type == 'text') {
val = document.imageSearchForm.elements[i].value;
}
if (val.length() > 0 || document.imageSearchForm.elements[i].type
!= 'select-multiple') {
qs += escape(document.SearchForm.elements[i].name) + '=' + val;
}
val = '';
}
alert('qs = ' + qs);
link.href += qs;
alert(link.href);
}
</script>

<a id="myLink" href="blah.php?stuff=blah&hasStuff=1"
onClick="addFieldsToLink(this)">Click</a>

I am trying to create a cross-browser JS function that, upon clicking
a link, will build upon the existing link an extension query string of
all form elements that the user enter to retain them in another
document.

Unfortunately I cannot verify if this works in Mozilla Firefox nor in
Konqueror because I am unable to install the JS plug-in successfully
for Mozilla Firefox and this is a Linux shop (i.e. it's MS-free) so I
have no ability to use IE to verify errors (and cannot install
Netscape due to not having root permission to install it.. life is
grand!).

So unfortunately, I cannot verify on my own if this works other than
the fact that I know that at the very least it is not adding the query
string generated in the JS local variable "val" into link.href in the
function because the resulting document does not have any additional
elements that would have been gleaned from the query-string in its
entirely prior to redirection to that new document upon clicking.

So now I need some JS help from folks that might have done something
similar to this, any ideas where I might have gone wrong and what I
should do to be able to accomplish this task?

Thanx
Phil
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Variable variable name" or "variable lvalue" mfglinux Python 11 09-12-2007 03:08 AM
adding a variable name to a hash to name is part of the variable name Bobby Chamness Perl 2 04-22-2007 09:54 PM
adding a method and a variable with BCEL lemonj@gmail.com Java 1 09-07-2005 12:40 PM
How do I scope a variable if the variable name contains a variable? David Filmer Perl Misc 19 05-21-2004 03:55 PM
adding a variable inside a hyperlink template (inside a datalist) Dave ASP .Net 0 08-29-2003 08:12 PM



Advertisments