Solved

how to remove drop down values while adding

Posted on 2014-11-11
8
185 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 7

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 7

Expert Comment

by:Mukesh Yadav
ID: 40436814
On form's onBeforeSubmit event check for select Head Value if found remove those heads.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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 7

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
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…

813 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

10 Experts available now in Live!

Get 1:1 Help Now