passing a field value in href

X

Xerxes

Hi all,
I am trying to pass a value of a field as an argument to href but I am
not doing it right:

<select name="sel_name" id="sel_id"><option>....</option>....

<a href="somefile.php?new=1&s=?????>text</a>

I tried to replace ???? with:
document.getElementById['sel_id'].options[document.getElementById['sel_id'].selectedIndex].text

didn't work.

I tried to set a hidden field's value when selection changed and use
that value for ???? but that didn't work either.

<select name="sel_name" id="sel_id"
onChange=document.getElementById['hidden'].value=this.options[this.selectedIndex].text"><option>....</option>....
....
<a href="somefile.php&new=1&s=document.getElementById['hidden'].value>
 
L

Lee

Xerxes said:
Hi all,
I am trying to pass a value of a field as an argument to href but I am
not doing it right:

<select name="sel_name" id="sel_id"><option>....</option>....

<a href="somefile.php?new=1&s=?????>text</a>

I tried to replace ???? with:
document.getElementById['sel_id'].options[document.getElementById['sel_id'].selectedIndex].text

didn't work.

I tried to set a hidden field's value when selection changed and use
that value for ???? but that didn't work either.

<select name="sel_name" id="sel_id"
onChange=document.getElementById['hidden'].value=this.options[this.selectedIndex].text"><option>....</option>....
...
<a href="somefile.php&new=1&s=document.getElementById['hidden'].value>

Just name the hidden field "s" and let the browser's normal
submit functionality add it to the query string.
 
M

marss

Xerxes said:
Hi all,
I am trying to pass a value of a field as an argument to href but I am
not doing it right:

<select name="sel_name" id="sel_id"><option>....</option>....

<a href="somefile.php?new=1&s=?????>text</a>

I tried to replace ???? with:
document.getElementById['sel_id'].options[document.getElementById['sel_id'].selectedIndex].text

didn't work.

I tried to set a hidden field's value when selection changed and use
that value for ???? but that didn't work either.


<a href="javascript:document.location.assign('somefile.php&new=1&s=' +
document.getElementById('sel_id').options[document.getElementById('sel_id').selectedIndex].text);">Link</a>
 
R

Randy Webb

marss said the following on 3/16/2006 2:02 AM:
Xerxes said:
Hi all,
I am trying to pass a value of a field as an argument to href but I am
not doing it right:

<select name="sel_name" id="sel_id"><option>....</option>....

<a href="somefile.php?new=1&s=?????>text</a>

I tried to replace ???? with:
document.getElementById['sel_id'].options[document.getElementById['sel_id'].selectedIndex].text

didn't work.

I tried to set a hidden field's value when selection changed and use
that value for ???? but that didn't work either.


<a href="javascript:document.location.assign('somefile.php&new=1&s=' +
document.getElementById('sel_id').options[document.getElementById('sel_id').selectedIndex].text);">Link</a>

Before posting here, endeavor yourself and take the time to read this
groups FAQ. Especially http://jibbering.com/faq/#FAQ4_24

<a href="noscript.html" onclick="document.location.href=....;return
false">Link Text</a>

And then, you won't be propagating bad habits.
 
M

marss

Randy said:
Before posting here, endeavor yourself and take the time to read this
groups FAQ. Especially http://jibbering.com/faq/#FAQ4_24

<a href="noscript.html" onclick="document.location.href=....;return
false">Link Text</a>

And then, you won't be propagating bad habits.

1.I carefully read faq 4.24 and I am not sure that my code so terrible.

The ideas that are stated there is pure theory, I was acquainted with
them before.
Number of people that use browsers with unsupported or disabled scripts
too small.
The most of software are made with the expectation of normal users
rather than few retrogrades.
2.Problem with browsers which do not understand javascript, or have it
disabled,
should be resolved at the whole page level rather then for each link
separately.
3.This task does not have decision without using javascript.
Therefore "document.location.assign(..." is not worse then
"document.location.href=....".

Sorry for my English.
 
R

Randy Webb

marss said the following on 3/16/2006 8:56 AM:
1.I carefully read faq 4.24 and I am not sure that my code so terrible.

It is. You did not bother to understand it is all. And maybe read the
Notes page on it. It has a very serious drawback to it.
The ideas that are stated there is pure theory, I was acquainted with
them before.

They are not "pure theory" the problem with a javascript: URL is very
well known.
Number of people that use browsers with unsupported or disabled scripts
too small.
The most of software are made with the expectation of normal users
rather than few retrogrades.

That is not the only problem with it.

<img src="someAnimatedGif.gif">
<a href="javascript:alert('Watch the animated Gif')">Test it</a>

Run that through IE and get back to me.
2.Problem with browsers which do not understand javascript, or have it
disabled, should be resolved at the whole page level rather then for
each link separately.

Absolutely. And part of doing that is not making your links JS
dependent. Then you have nothing else to worry about.
3.This task does not have decision without using javascript.
Therefore "document.location.assign(..." is not worse then
"document.location.href=....".

My comments had nothing to do with assign versus href. It had to do,
directly, with the use of the javascript: pseudo-protocol.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top