Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 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; 07-04-2002 at 06:25 AM.

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    document.forms["yourformname"].elements["attr_value1"].options[document.forms["yourformname"].elements["attr_value1"].selectedIndex].value
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    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;

  • #5
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    http://www.uniquely-ukraine.com/uniq...&pf%5Fid=11011
    Last edited by smithpe; 07-03-2002 at 09:58 PM.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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. ;)

  • #7
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi

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

    Paul

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Huh?
    Former ASP Forum Moderator - I'm back!

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

  • #9
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    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; 07-05-2002 at 07:32 AM.

  • #10
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!:

    http://msdn.microsoft.com/library/de...p/asps6hmb.asp
    http://www.w3schools.com/asp
    http://www.aspalliance.com
    http://www.haneng.com
    http://www.liquidrage.com

    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; 07-05-2002 at 11:30 PM.
    Former ASP Forum Moderator - I'm back!

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •