Web Analytics Made Easy -
StatCounter getting the value of selected item in a form - CodingForum

getting the value of selected item in a form

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • smithpe
    New to the CF scene
    • Jul 2002
    • 5

    getting the value of selected item in a form

    Hi

    I am trying with no luck to retrieve the value of a selected item in a drop down menu. I need to get this value so I can pass it along in another form.

    Here is the code for the first form

    Code:
    <SELECT NAME="attr_value1" >  
            <OPTION VALUE="1">1
            <OPTION VALUE="2">2
            <OPTION VALUE="3">3
            <OPTION VALUE="4">4
            <OPTION VALUE="5">5
            <OPTION VALUE="6">6
            <OPTION VALUE="7">7
            <OPTION VALUE="8">8 
    </SELECT>
    Any help will be greatly appreciated

    Thanks

    Paul
    Last edited by smithpe; Jul 4, 2002, 01:25 AM.
  • Spookster
    Supreme Overlord

    • May 2002
    • 6934

    #2
    document.forms["yourformname"].elements["attr_value1"].options[document.forms["yourformname"].elements["attr_value1"].selectedIndex].value
    Spookster
    CodingForum Supreme Overlord
    All Hail Spookster

    Comment

    • smithpe
      New to the CF scene
      • Jul 2002
      • 5

      #3
      Thanks

      In other words something like this

      Code:
      <script language="JavaScript">
      labelval=""
      for (var usedattr=1; usedattr< maxlabel; usedattr++) {
      	if (usedattr==1) {
      		labelval=document.forms["multiattrib"].elements["attr_value(usedattr)"].options[document.forms["multiattrib"].elements["attr_value(usedattr)"].selectedIndex].value	
      	else
      		labelval=document.forms["multiattrib"].elements["attr_value(usedattr)"].options[document.forms["multiattrib"].elements["attr_value(usedattr)"].selectedIndex].value	}
      }
      </script>

      Comment

      • adios
        CodingForum Senior
        • Jun 2002
        • 1404

        #4
        You've got a bunch of stuff in there, without the HTML that generated it or a description of what you're trying to do. Hard to analyze...

        var sel = document.form_name.select_name;
        var selVal = sel[sel.selectedIndex].value;

        Comment

        • smithpe
          New to the CF scene
          • Jul 2002
          • 5

          #5
          I am trying to pull the value of the selected item from the drop down menu. There can be a total of up to 5

          here is the code for the form
          Code:
          <SELECT NAME="attr_value<%= attr %>" >  
                  <%
                  set mva_valueField = rsMVAttr("mva_value")
                  do while Not rsMVAttr.EOF
                      %>
                      <%= mscsPage.Option(mva_valueField.value, 0) & mva_valueField.value%> 
                      <% rsMVAttr.MoveNext
          
                  loop
                  maxlabel=attr%> 
                          if label<>"" then
                  	label=label&","&attr_label(attr)
                  else
                  	label=attr_label(attr)
                  end if
                  rsMVAttr.Close
                  %>
                  </SELECT>
          Here is the script I am trying to use

          Code:
          <script language="JavaScript">
          labelval=""
          for (var usedattr=1; usedattr< maxlabel; usedattr++) {
          	if (usedattr==1) {
          		labelval=document.forms["multiattrib"].elements["attr_value(usedattr)"].options[document.forms["multiattrib"].elements["attr_value(usedattr)"].selectedIndex].value	
          	else
          		labelval=document.forms["multiattrib"].elements["attr_value(usedattr)"].options[document.forms["multiattrib"].elements["attr_value(usedattr)"].selectedIndex].value	}
          }
          </script>
          Here is a link to the page.
          Last edited by smithpe; Jul 3, 2002, 04:58 PM.

          Comment

          • whammy
            CodingForum Senior
            • Jun 2002
            • 3687

            #6
            If you're trying to do it client side, just pass the value to a function, or whatever... here's the easiest way to get a dropdown menu's value - I'll use an alert box for an example:

            Code:
            <select name="blah" onchange="alert(this.options[this.selectedIndex].value)">
            <option value="1">1</option>
            <option value="2">2</option>
            </select>
            Former ASP Forum Moderator - I'm back!

            If you can teach yourself how to learn, you can learn anything. ;)

            Comment

            • smithpe
              New to the CF scene
              • Jul 2002
              • 5

              #7
              Hi

              I have tried the OnChange method but if they select all of the default it won't work.

              Paul

              Comment

              • whammy
                CodingForum Senior
                • Jun 2002
                • 3687

                #8
                Huh?
                Former ASP Forum Moderator - I'm back!

                If you can teach yourself how to learn, you can learn anything. ;)

                Comment

                • smithpe
                  New to the CF scene
                  • Jul 2002
                  • 5

                  #9
                  Ok let try to explain a little better what I am trying to do

                  I have a page with 2 forms on it. The first form can have up to 5 drop down menus with attributes of the item ordered.
                  here is the code for the drop down menus.
                  Code:
                   <TD><%= attr_label(attr) %>:</TD>
                          <TD>
                          <SELECT NAME="attr_value<%= attr %>" >  
                          <%
                          set mva_valueField = rsMVAttr("mva_value")
                          do while Not rsMVAttr.EOF
                              %>
                              <%= mscsPage.Option(mva_valueField.value, 0) & mva_valueField.value%> 
                              <% rsMVAttr.MoveNext
                  
                          loop
                          
                          maxlabel=attr%> 
                          <!-- save number of attribs for paypal cart -->
                          <!-- get the attrib labels for paypal --><%
                          if label<>"" then
                          	label=label&","&attr_label(attr)
                          else
                          	label=attr_label(attr)
                          end if
                          rsMVAttr.Close
                          %>
                          </SELECT>
                          </TD>
                  I have a second form that calls a different page on submission, but I need the values of the selected attributes in the drop down menus of the first form. I have been able to use code similar to what was posted here to fire off an alert box when the selected items change. What I really need to do is when the second form is submitted is to grab the values of all the selected items in the drop down menus from the first form. Please feel free to look at the page I am working on at here is the page I am working on
                  Last edited by smithpe; Jul 5, 2002, 02:32 AM.

                  Comment

                  • whammy
                    CodingForum Senior
                    • Jun 2002
                    • 3687

                    #10
                    This is an ASP page... all you need to do to get the values, first of all, is *not* use javascript - you might as well use .asp to its potential, since it's designed to do exactly what you want (pass information from one page to another, etc. etc. etc.):

                    <%
                    Dim attr_value1
                    attr_value1 = Request.Form("attr_value1")

                    Response.Write(attr_value1)
                    %>

                    Use the code above, and you'll see that you can very easily get the values of (any) dropdown on the next page using .asp.

                    Just do the same with each <select> elements' value on the previous page, and you can get them all just as easily.

                    P.S. This is a fairly basic thing in ASP, I would recommend some tutorials, here's a few food websites for them!:


                    W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.


                    Expert in innovation, sustainability and technology. Keynote speaker. Director of Innovation and Sustainability at the Norwegian Federation of Service Industries and Retail Trade



                    I would also do a bit of research into the differences between "client-side" and "server-side" - someone here had a really good article on that, but unfortunately I've since lost the link

                    Javascript *can* pass values from page to page (but it's more complicated) - but why use javascript when you have the ability to use ASP?

                    Hope that helps!

                    Last edited by whammy; Jul 5, 2002, 06:30 PM.
                    Former ASP Forum Moderator - I'm back!

                    If you can teach yourself how to learn, you can learn anything. ;)

                    Comment

                    Working...
                    X