JavaScript DOM Get Value from Form

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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gurvinder Pal SinghCommented:
can you try to alert the following?


$('select#type option[selected]').val()
Gurvinder Pal SinghCommented:
just check if there is any other element called 'type' in your DOM
try renaming it to 'type1'

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GVNPublic123Author Commented:
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.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.