Getting the value of one textbox in an array.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andyza

    Getting the value of one textbox in an array.

    I have a form with a number of textboxes. Each textbox has the same
    name.

    <input type="text" name="txtTest" value="1" onclick="GetVal ue()">
    <input type="text" name="txtTest" value="2" onclick="GetVal ue()">
    <input type="text" name="txtTest" value="3" onclick="GetVal ue()">
    <input type="text" name="txtTest" value="4" onclick="GetVal ue()">
    <input type="text" name="txtTest" value="5" onclick="GetVal ue()">

    To loop through the textboxes and retrieve the value of each box I use
    this loop:

    <script language="javas cript">
    function GetValue() {
    for (i=0; i<document.form s[0].txtTest.length ; i++){
    alert(document. forms[0].txtTest[i].value)
    }
    }
    </script>

    GetValue() gives me an array with the values of all the textboxes. How
    do I get the function to return JUST the value of the textbox that I
    clicked on?

    Example, if I click on the third textbox it will display an alert with
    3 and if I click on the first textbox it will display an alert with 1.

    Thanks
  • Martin Honnen

    #2
    Re: Getting the value of one textbox in an array.

    Andyza wrote:
    GetValue() gives me an array with the values of all the textboxes. How
    do I get the function to return JUST the value of the textbox that I
    clicked on?
    function getValue (input) {
    alert(input.val ue);
    }

    <input onclick="getVal ue(this);" ...>


    --

    Martin Honnen

    Comment

    Working...