How can I get a form variable if the name is a parameter?

Discussion in 'JavaScript' started by celia05es, Jan 30, 2007.

  1. #1
    Hello,
    I have the following form that contains various parameters P1..... P10. I only give the example for P1 and P2:
    
    <form onSubmit="return false" method="post" name="parameters" action="">
    <table border=0>
    <tr>
    <td>P1:</td>
    <%
    a vector v will contain the correct list
    %>
    <td><select name="p1"  onChange="getSelect(this)">  
    <%
        for (int k=0;k<v.size();k++)
        {
    %>
          <option value="<%=v.elementAt(k)%>"><%=v.elementAt(k)%></option>
    <%
        }
    %>
    </select></td>
    <td>
    <input type="button" onClick="reDirect('p1')" value="Modify"></td>
    <tr>
    <tr>
    <td>P2:</td>
    <%
    The vector v will contain the correct list
    %>
    <td><select name="p2"  onChange="getSelect(this)">  
    <%
        for (int k=0;k<v.size();k++)
        {
    %>
          <option value="<%=v.elementAt(k)%>"><%=v.elementAt(k)%></option>
    <%
        }
    %>
    </select></td>
    <td>
    <input type="button" onClick="reDirect('p2')" value="Modify"></td>
    </table>
    </form>
    
    Code (markup):
    Now, inside the javascript function reDirect(fieldName) I would like to get the content of the fieldName as follows:
    
    function reDirect(fieldName)
    {
    .....
    fieldName=document.parameters.p1.value; or
    fieldName = document.parameters.p2.value 
    but with only one line and having fieldName instead of "p1" or "p2".
    }
    
    Code (markup):
    In other words, I would like to find a way of getting the parameter value doing:
    document.parameters.<fieldName>.value.

    Is there a way of doing it?

    THank you for your help.
     
    celia05es, Jan 30, 2007 IP
  2. celia05es

    celia05es Guest

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Problem solved with getElementbyId.
     
    celia05es, Jan 30, 2007 IP