href with variable in link

Discussion in 'Javascript' started by ntdude4@hotmail.com, May 21, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. Evertjan. Guest

    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)
     
    Evertjan., May 21, 2006
    #2
    1. Advertising

  3. 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.
     
    Michael Winter, May 22, 2006
    #3
  4. Evertjan. Guest

    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)
     
    Evertjan., May 22, 2006
    #4
  5. Guest

    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, 2006
    #5
  6. Randy Webb Guest

    said the following on 5/22/2006 3:44 PM:
    > 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/
     
    Randy Webb, May 22, 2006
    #6
  7. Guest

    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, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CRON
    Replies:
    24
    Views:
    203,050
    Adrienne Boswell
    Jun 20, 2006
  2. Soren Vejrum
    Replies:
    4
    Views:
    687
    Lasse Reichstein Nielsen
    Jul 5, 2003
  3. saiho.yuen
    Replies:
    3
    Views:
    472
    kaeli
    Sep 14, 2004
  4. Replies:
    2
    Views:
    543
  5. Vincent van Beveren

    BASE HREF and A HREF="#" onclick="..."

    Vincent van Beveren, Jul 6, 2006, in forum: Javascript
    Replies:
    2
    Views:
    360
    Vincent van Beveren
    Jul 6, 2006
Loading...

Share This Page