Solved

how to remove drop down values while adding

Posted on 2014-11-11
8
199 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
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)

733 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