Connecting Tech Pros Worldwide Forums | Help | Site Map

passing a field value in href

Xerxes
Guest
 
Posts: n/a
#1: Mar 15 '06
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>


marss
Guest
 
Posts: n/a
#2: Mar 16 '06

re: passing a field value in href



Xerxes wrote:[color=blue]
> 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.[/color]


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

Randy Webb
Guest
 
Posts: n/a
#3: Mar 16 '06

re: passing a field value in href


marss said the following on 3/16/2006 2:02 AM:[color=blue]
> Xerxes wrote:[color=green]
>> 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.[/color]
>
>
> <a href="javascript:document.location.assign('somefil e.php&new=1&s=' +
> document.getElementById('sel_id').options[document.getElementById('sel_id').selectedIndex].text);">Link</a>[/color]

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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
marss
Guest
 
Posts: n/a
#4: Mar 16 '06

re: passing a field value in href



Randy Webb wrote:[color=blue]
> 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.
>
> --
> Randy
> comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
> Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/[/color]

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.

Randy Webb
Guest
 
Posts: n/a
#5: Mar 18 '06

re: passing a field value in href


marss said the following on 3/16/2006 8:56 AM:[color=blue]
> Randy Webb wrote:[color=green]
>> 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.
>>
>> --
>> Randy
>> comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
>> Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/[/color]
>
> 1.I carefully read faq 4.24 and I am not sure that my code so terrible.[/color]

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.
[color=blue]
> The ideas that are stated there is pure theory, I was acquainted with
> them before.[/color]

They are not "pure theory" the problem with a javascript: URL is very
well known.
[color=blue]
> 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.[/color]

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.
[color=blue]
> 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.[/color]

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

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

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Closed Thread