href with variable in link

N

ntdude4

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
 
E

Evertjan.

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:

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
 
M

Michael Winter

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
 
E

Evertjan.

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.
 
P

pegasusflightresources

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.
 
R

Randy Webb

(e-mail address removed) said the following on 5/22/2006 3:44 PM:
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.

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..
 
N

ntdude4

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
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top