Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Auto Select UnSelected Items on Form Submitt

Posted on 2010-08-26
Medium Priority
Last Modified: 2012-05-10

I would like to default un-selected options to No XYZ on form submit.

Is this hard to do with Javascript? If not, how would you do it - simplest way possible.
Question by:stroudtx
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 11

Accepted Solution

John Easton earned 1500 total points
ID: 33537039
Hi Stroudtx,

I assume you do not want the default to be the 'none' option.  Therefore I would add a function which checks to see if the value of each select is less than 0 (i.e. not selected an option) and if so change it to the desire option.  Something like the below should work (although my JavaScript is not great so please check the syntax).

if (document.getElementById('option1').value < 0) {
document.getElementById('option1').value = "0|"

Hope this helps


Author Closing Comment

ID: 33605478
Thanks - I"ll give it a try

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

604 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