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
Solved

how to remove drop down values while adding

Posted on 2014-11-11
8
191 Views
Last Modified: 2014-11-18
Hi ,

I have dropdown which is dynamically created .(user how many need the will create that much drop down box).

I want to remove the drop down box with out value while saving time .. how to do that ?

div id="headNo1">
<select name="headNo1" id="headNo1">
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
	<option value="4">4</option>
	<option value="5">5</option>
	<option value="6">6</option>
	<option value="7">7</option>
	<option value="8">8</option>
	<option value="9">9</option>
</select>
</div>
<div id="headNo2">
<select name="headNo2" id="headNo2">
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
	<option value="4">4</option>
	<option value="5">5</option>
	<option value="6">6</option>
	<option value="7">7</option>
	<option value="8">8</option>
	<option value="9">9</option>
</select>
</div>
<div id="headNo3">
<select name="headNo3" id="headNo3">
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
	<option value="4">4</option>
	<option value="5">5</option>
	<option value="6">6</option>
	<option value="7">7</option>
	<option value="8">8</option>
	<option value="9">9</option>
</select>
</div>

                

Open in new window

0
Comment
  • 4
  • 3
8 Comments
 
LVL 8

Expert Comment

by:Mukesh Yadav
ID: 40436759
Please elaborate your problem...
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 40436803
I have dropdown which is dynamically created by user how much they need . In below code it will add headno1  to headno(n) value.

for example :user create 5 drop downs .

headno1,headno2,headno3,headno4,headno5

but the fill only 3 values  remain 2 values are select Head Value

headno1 =5
headno2=select Head Value
headno3 =4
headno4 =9
headno5 =select Head value


While adding(Saving) i want to remove headno2,headno5  and pass remaining 3 values to back end

like that i want to .. How to achieve this ??
div id="headNo1">
<select name="headNo1" id="headNo1">
       <option value="x">Select Head Value</option>
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
	<option value="4">4</option>
	<option value="5">5</option>
	<option value="6">6</option>
	<option value="7">7</option>
	<option value="8">8</option>
	<option value="9">9</option>
</select>
</div>
<div id="headNo2">
<select name="headNo2" id="headNo2">
               <option value="x">Select Head Value</option>
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
	<option value="4">4</option>
	<option value="5">5</option>
	<option value="6">6</option>
	<option value="7">7</option>
	<option value="8">8</option>
	<option value="9">9</option>
</select>
</div>
<div id="headNo3">
<select name="headNo3" id="headNo3">
       <option value="x">Select Head Value</option>
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
	<option value="4">4</option>
	<option value="5">5</option>
	<option value="6">6</option>
	<option value="7">7</option>
	<option value="8">8</option>
	<option value="9">9</option>
</select>
</div>

Open in new window

0
 
LVL 8

Expert Comment

by:Mukesh Yadav
ID: 40436814
On form's onBeforeSubmit event check for select Head Value if found remove those heads.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 40436851
Save button is a image , So when click the image i want to remove that time
0
 
LVL 8

Expert Comment

by:Ahmed Merghani
ID: 40436854
On the back-end, you can check the value of the inputs before save it and if the value equal "x" just ignore it.
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 40436868
Ahmed Merghani--------- Thanks for your Info ....  :D :D ..



That drop down list is used lot of files and lot of tables so that is not possible in back end ... Some condition and some other screen  i need to add x value ....

So that is not possible before saving ....
0
 
LVL 8

Accepted Solution

by:
Mukesh Yadav earned 500 total points
ID: 40436910
add following function anywhere in your file:-

<script>
function checkForValue(elementIds){
  for(var i in elementIds){
    if(document.getElementById(elementIds[i]).selectedIndex == 0){
      /* this will remove select element from the DOM and this filed won't be submitted with form data. */
      document.getElementById(elementIds[i]).outerHTML='';
    }
  }
}
</script>

Open in new window


and add following code to onClick event handler of input tag having type as image.

javascript: checkForValue(['headNo1', 'headNo2', 'headNo3', 'headNo4', 'headNo1']);document.getElementById('formId').submit();

Open in new window


Please remember to update proper id for headNo1 to headNo5 and for formId
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 40439144
thanks Mukesh Yadav... Its not generic thats is the problem . Can you help to make it generic one .
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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…

828 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