JavaScript DOM Get Value from Form

Posted on 2011-10-04
Last Modified: 2012-05-12
Ok, here is the problem that I have right now. I want to submit form via AJAX and display fancy message, without need to go to other pages or reload. Which is working fine, except for 1 thing.

When I attempt to get values from form, the issue is with <select>:
<select name="type" id="type"><option value="1">Network Promotion</option><option selected value="2">Regular Promotion</option></select>

Open in new window

Ive tried with:
var type=encodeURIComponent(document.getElementById("type").value)

Open in new window

But it always outputs 0, and no value of selected index.

Ive also tried gettin DOM without value and than:

Open in new window

But that just crashes the script...

So please, can anyone help me out and give me cross-browser solution that works?
Question by:GVNPublic123
    LVL 40

    Expert Comment

    can you try to alert the following?


    LVL 15

    Expert Comment

    $('select#type option[selected]').val()
    LVL 40

    Accepted Solution

    just check if there is any other element called 'type' in your DOM
    try renaming it to 'type1'

    Author Comment

    gurvinder I guess type was too generic. Now it works.

    I hope this is cross-browser however, I have a legacy tool on site as well, just in case if ajax doesnt work for someone AND notification for javascript if its not installed/enabled.


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    ASP.NET AJAX callbacks to web service are becoming very popular and unavoidable these days. The feel that the user gets when only a part of the page is updated without even hindering the UI is the advantage that the callbacks offer. The wait for the…
    Introduction HyperText Transfer Protocol ( or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now