Get value from button

Discussion in 'Javascript' started by bonAveo.net, Jun 20, 2005.

  1. bonAveo.net

    bonAveo.net Guest

    Hi,
    I got 3 buttons with 3 different values...

    > <input type="image" src="search.png" value="http://jigsaw.w3.org/css-validator/validator?usermedium=all&uri=" onclick="addUrl(this.value)">
    > <input type="image" src="search.png" value="http://validator.w3.org/check?uri=" onclick="addUrl(this.value)">
    > <input type="image" src="search.png" value="http://validator.w3.org/checklink?hide_redirects=on&hide_type=all&recursive=on&depth=1&check=Check&uri=" onclick="addUrl(this.value)">


    ....and I want the value from the button pressed into this:

    > function goTo() {
    >
    > var adress = document.getElementById("seee");
    > var link = document.getElement("addUrl");
    >
    > var url = link + adress;
    > (...something, something...)
    > }


    What have I done wrong?
    bonAveo.net, Jun 20, 2005
    #1
    1. Advertising

  2. bonAveo.net wrote:
    > Hi, I got 3 buttons with 3 different values...
    >
    >
    >> <input type="image" src="search.png"
    >> value="http://jigsaw.w3.org/css-validator/validator?usermedium=all&uri="
    >> onclick="addUrl(this.value)"> <input type="image" src="search.png"
    >> value="http://validator.w3.org/check?uri="
    >> onclick="addUrl(this.value)"> <input type="image" src="search.png"
    >> value="http://validator.w3.org/checklink?hide_redirects=on&hide_type=all&recursive=on&depth=1&check=Check&uri="
    >> onclick="addUrl(this.value)">


    where is your addUrl function?

    You may probably want something like

    function addUrl(val) {
    document.getElementById("seee").value += val;
    }


    >> function goTo() {
    >>
    >> var adress = document.getElementById("seee");


    I don't see an element with ID "seee"


    >> var link = document.getElement("addUrl");


    I don't see an element with ID "addUrl"


    >> var url = link + adress;


    "link" and "adress" are object references in this case. If they
    reference a button, you need to get their values:


    var url = link.value + adress.value;

    Daniel
    Daniel Kirsch, Jun 20, 2005
    #2
    1. Advertising

  3. bonAveo.net

    bonAveo.net Guest

    OK; heres my "whole" code:

    function goTo() {

    var adress = document.getElementById("seee");
    var link = document.getElement("addUrl");

    var url = link + adress;
    alert(url);
    if (window.widget) widget.;
    site.value="";
    }



    ....and...


    <form class="felt" method="get" action="javascript:goTo()">
    <!-- Searchfield -->
    <input id="seee" type="text" size="16" maxlength="255" value="" />
    <!-- Searchfield end -->
    <br />
    <input type="image" src="search.png"
    value="http://jigsaw.w3.org/css-validator/validator?usermedium=all&uri="
    onclick="addUrl(this.value)">
    <input type="image" src="search.png"
    value="http://validator.w3.org/check?uri="
    onclick="addUrl(this.value)">
    <input type="image" src="search.png"
    value="http://validator.w3.org/checklink?hide_redirects=on&hide_type=all&recursive=on&depth=1&check=Check&uri="
    onclick="addUrl(this.value)">
    </form>


    I don't understand why the value from the pressed button don't aply in
    the JavaScript.
    bonAveo.net, Jun 20, 2005
    #3
  4. bonAveo.net

    Lee Guest

    bonAveo.net said:
    >
    >OK; heres my "whole" code:
    >
    >function goTo() {
    >
    > var adress = document.getElementById("seee");
    > var link = document.getElement("addUrl");
    >
    > var url = link + adress;
    > alert(url);
    > if (window.widget) widget.;
    > site.value="";
    >}
    >
    >
    >
    >...and...
    >
    >
    ><form class="felt" method="get" action="javascript:goTo()">
    > <!-- Searchfield -->
    > <input id="seee" type="text" size="16" maxlength="255" value="" />
    > <!-- Searchfield end -->
    > <br />
    > <input type="image" src="search.png"
    >value="http://jigsaw.w3.org/css-validator/validator?usermedium=all&uri="
    >onclick="addUrl(this.value)">
    > <input type="image" src="search.png"
    >value="http://validator.w3.org/check?uri="
    >onclick="addUrl(this.value)">
    > <input type="image" src="search.png"
    >value="http://validator.w3.org/checklink?hide_redirects=on&hide_type=all&recursive=on&depth=1&check=Check&uri="
    >onclick="addUrl(this.value)">
    > </form>
    >
    >
    >I don't understand why the value from the pressed button don't aply in
    >the JavaScript.


    You seem to be making wildly incorrect guesses about what should work.
    You still haven't shown any code for your addUrl() function.
    Are you expecting getElement("addUrl") to return the argument passed to that
    (undefined) function? It doesn't work that way.
    You should very rarely use an input of type image unless you want clicking on it
    to submit a form.
    You shouldn't have a javascript function as the action of your form.
    You seem to be trying to generate an URL by concatinating a reference to an
    input element with a reference to a function.
    The last two lines of your function goTo() don't make any sense at all.
    Lee, Jun 20, 2005
    #4
  5. bonAveo.net wrote:
    > var url = link + adress;


    Once again.
    "link" and "adress" are object references in this case. If they
    reference a button, you need to get their values:

    var url = link.value + adress.value;

    However I still don't see any element with id="addUrl" so

    var link = document.getElement("addUrl");

    will probably not even contain a valid reference.

    Daniel
    Daniel Kirsch, Jun 21, 2005
    #5
  6. bonAveo.net

    Randy Webb Guest

    Daniel Kirsch wrote:
    > bonAveo.net wrote:
    >
    >> var url = link + adress;

    >
    >
    > Once again.
    > "link" and "adress" are object references in this case. If they
    > reference a button, you need to get their values:
    >
    > var url = link.value + adress.value;
    >
    > However I still don't see any element with id="addUrl" so
    >
    > var link = document.getElement("addUrl");
    >
    > will probably not even contain a valid reference.


    Even if addUrl existed, document.getElement(anything) wouldnt contain a
    valid reference unless getElement was a author-defined function.
    document.getElementByID('addUrl') might contain a valid reference though.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Randy Webb, Jun 21, 2005
    #6
  7. Randy Webb wrote:
    > Even if addUrl existed, document.getElement(anything) wouldnt contain a
    > valid reference unless getElement was a author-defined function.


    Absolutely.
    Daniel Kirsch, Jun 21, 2005
    #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. Fredrik Lundh
    Replies:
    0
    Views:
    381
    Fredrik Lundh
    Jul 6, 2006
  2. Hiten
    Replies:
    1
    Views:
    618
    Vidar Petursson
    May 26, 2004
  3. Lukelrc
    Replies:
    3
    Views:
    137
    Luke Curtis
    Jun 9, 2004
  4. Chuck
    Replies:
    0
    Views:
    257
    Chuck
    Nov 10, 2003
  5. Replies:
    0
    Views:
    205
Loading...

Share This Page