473,382 Members | 1,435 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

href with variable in link

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
6 14989
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
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
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

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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Sorby | last post by:
Hi I've been coding in PHP for a little while now and was starting to feel pretty confident but then realise I need to understand regular expressions to solve a particular problem I've got ......
3
by: Paul Eghbal | last post by:
Hi all, I'm trying to use the following script: <script language="javaScript"> function setrepto(){ document.aForm.repno.value = document.aForm.rep.options.value; } </script>
11
by: Dana Smith | last post by:
Can anybody explain why when I have a hyperlink on a page with the code similar to below, after the user clicks on the link, the desired window opens but the page with the hyperlink changes to a...
5
by: Jack | last post by:
Hi, I need to pass multple variables in a link in order to go to a asp page with the two varables. The following are the values of the variables using response.write: <%'Response.Write Mypage...
2
by: Kevin Lyons | last post by:
Hello, Can anyone assist me with what I am trying to do with the following code (six different scenarios to try to make the functionality work correctly)? I want to always (and ONLY) display...
53
by: usenet | last post by:
See <ul> <li><a name="link1" onClick="alert(this.name);return false;" href="#">Link1</a></li> <li><a name="link2" href="javascript:alert(this);">Link2</a></li> <li>Item 3</li> </ul> ...
2
by: +The_Taco+ | last post by:
I already use session variable in my project to set a session timeout when the user doesn't do anything for 10 minutes. When I call other pages, I often use parameters in HREF link. I was...
11
by: coflo | last post by:
Hello I would like to replace an a href link that is provided in the RSS below with my own link. The link that I am looking to replace is defined in the <description> tag within the RSS. Im...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.