By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,106 Members | 2,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,106 IT Pros & Developers. It's quick & easy.

href with variable in link

P: n/a
I am trying to make a variable link on a page. The page has a text box
for a stock symbol. The code is: <input type=TEXTBOX Name="symtb"
value="" size="10>
The value of the text box {the stock symbol} will complete the url.

I found code for a variable link:
<script language="JavaScript">
<!--
function variable_in_link(varible_value)
{
new_win = window.open('http://finance.yahoo.com/q?s=" +
varible_value'')
}
// -->
</script>

The link I am trying to use is: <a
href="javascript:variable_in_link(symtb)">The text</a>

No matter what I do the variable_value comes back as undefined. There
is always a value in the text box.

Any ideas what is going on?

thanks

vm

May 21 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
wrote on 22 mei 2006 in comp.lang.javascript:
I am trying to make a variable link on a page. The page has a text box
for a stock symbol. The code is: <input type=TEXTBOX Name="symtb" value="" size="10>
TEXTBOX is not a type
"10 needs a closing "

use: type='text'
The value of the text box {the stock symbol} will complete the url.

I found code for a variable link:
<script language="JavaScript">
do not use language="JavaScript"
use:
<script type='text/javascript'>
<!--
do not use <!--
function variable_in_link(varible_value)
{
new_win = window.open('http://finance.yahoo.com/q?s=" +
varible_value'')
do not mix " and ', and wgy the '' in the end?
}
// -->
do not use // -->
</script>

The link I am trying to use is: <a
href="javascript:variable_in_link(symtb)">The text</a>
A link is for linking, use a button for js execution
a name in an input is not a js variable.
better use an id='..'
No matter what I do the variable_value comes back as undefined. There
is always a value in the text box.


"variable_value comes back" ???

Where does it come back???

A computer language is built by using statements and functions as
specified, not by trial because it sounds like English.

So read the specs of each used function and reasd the Faqs of this NG.

=====

try:

========= test.html ========

<script type='text/javascript'>

function doit() {
var x = document.getElementById('symtb').value
window.open('http://finance.yahoo.com/q?s='+x)
}

</script>

<input type='text' id='symtb' value='IBM' size='10'>
<br>
<button onclick='doit()'>Go!</button>

============================

TESTED
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 21 '06 #2

P: n/a
On 21/05/2006 23:38, Evertjan. wrote:

[snip]
<button onclick='doit()'>Go!</button>


You should be aware that IE and the HTML Specification differ in many
ways regarding the button element. The most significant, here, is that
the default type is actually submit, not button.

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
May 22 '06 #3

P: n/a
Michael Winter wrote on 22 mei 2006 in comp.lang.javascript:
On 21/05/2006 23:38, Evertjan. wrote:

[snip]
<button onclick='doit()'>Go!</button>


You should be aware that IE and the HTML Specification differ in many
ways regarding the button element. The most significant, here, is that
the default type is actually submit, not button.


This was outside a <form>, I submit.

However awareness is a bonus for programmers and the debuggers.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 22 '06 #4

P: n/a

nt*****@hotmail.com wrote:
I am trying to make a variable link on a page. The page has a text box
for a stock symbol. The code is: <input type=TEXTBOX Name="symtb"
value="" size="10>
The value of the text box {the stock symbol} will complete the url.

I found code for a variable link:
<script language="JavaScript">
<!--
function variable_in_link(varible_value)
{
new_win = window.open('http://finance.yahoo.com/q?s=" +
varible_value'')
}
// -->
</script>

The link I am trying to use is: <a
href="javascript:variable_in_link(symtb)">The text</a>

No matter what I do the variable_value comes back as undefined. There
is always a value in the text box.

Any ideas what is going on?

thanks

vm


You should change your script to something like this:
<script type="text/javascript">
function go_to_link(stocksymbol)
{
part_of_link = stocksymbol;
main_link = "http://finance.yahoo.com/q?s=";
full_link = main_link + part_of_link;
new_win = window.open(full_link);
}
</script>

Now change your <a> tag to say:
<a href="javascript:go_to_link(symtb)">The text</a>
By the way, you added an extra quotation mark (") after varible_value
in your window.open. That may be your original flaw, but this is just
a way to make sure that there is no larger problem.

I have the honor to remain your most humble and Ob't Sv't in our war
against the King.

--
Patrick Reilly
1st Coy.
Colonel Seth Warner's Regiment

May 22 '06 #5

P: n/a
pe********************@gmail.com said the following on 5/22/2006 3:44 PM:
nt*****@hotmail.com wrote:
I am trying to make a variable link on a page. The page has a text box
for a stock symbol. The code is: <input type=TEXTBOX Name="symtb"
value="" size="10>
The value of the text box {the stock symbol} will complete the url.

I found code for a variable link:
<script language="JavaScript">
<!--
function variable_in_link(varible_value)
{
new_win = window.open('http://finance.yahoo.com/q?s=" +
varible_value'')
}
// -->
</script>

The link I am trying to use is: <a
href="javascript:variable_in_link(symtb)">The text</a>

No matter what I do the variable_value comes back as undefined. There
is always a value in the text box.

Any ideas what is going on?

thanks

vm
You should change your script to something like this:
<script type="text/javascript">
function go_to_link(stocksymbol)
{
part_of_link = stocksymbol;


That variable is unneeded.
main_link = "http://finance.yahoo.com/q?s=";
That one is also.
full_link = main_link + part_of_link;
new_win = window.open(full_link);
Why all the extra crap for nothing?

new_win = window.open("http://finance.yahoo.com/q?s=" + stocksymbol);
}
</script>

Now change your <a> tag to say:
<a href="javascript:go_to_link(symtb)">The text</a>


NO. Don't change your link to that.

<URL: http://jibbering.com/faq/#FAQ4_24>

<a href="fullURLtoPage" target="new_win"
onclick="go_to_link(this.href,this.target)">

function go_to_link(hrefToUse,windowName){
window.open(hrefToUse,windowName)
}

That is assuming that window.open returns a new window..

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 22 '06 #6

P: n/a
Thanks to all. I put together bits and pieces of several posts to make
it do exactly what I need. I am still new to javascript and am no
longer able to use php.
Thanks again to all for the pointers and tips.

vm

May 22 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.