P
Phil Powell
<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.type == 'select-one') {
val = document.imageSearchForm.elements.options[document.imageSearchForm.elements.selectedIndex].value;
} else if (document.imageSearchForm.elements.type ==
'select-multiple') {
// DO NOT SET val HERE BUT ADD TO QS DIRECTLY
for (j = 0; j < document.imageSearchForm.elements.options.length;
j++) {
qs += '&' + escape(document.imageSearchForm.elements.name) +
'=' +
escape(document.imageSearchForm.elements.options[document.imageSearchForm.elements.selectedIndex].value);
}
} else if (document.imageSearchForm.elements.type == 'text') {
val = document.imageSearchForm.elements.value;
}
if (val.length() > 0 || document.imageSearchForm.elements.type
!= 'select-multiple') {
qs += escape(document.SearchForm.elements.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
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.type == 'select-one') {
val = document.imageSearchForm.elements.options[document.imageSearchForm.elements.selectedIndex].value;
} else if (document.imageSearchForm.elements.type ==
'select-multiple') {
// DO NOT SET val HERE BUT ADD TO QS DIRECTLY
for (j = 0; j < document.imageSearchForm.elements.options.length;
j++) {
qs += '&' + escape(document.imageSearchForm.elements.name) +
'=' +
escape(document.imageSearchForm.elements.options[document.imageSearchForm.elements.selectedIndex].value);
}
} else if (document.imageSearchForm.elements.type == 'text') {
val = document.imageSearchForm.elements.value;
}
if (val.length() > 0 || document.imageSearchForm.elements.type
!= 'select-multiple') {
qs += escape(document.SearchForm.elements.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