Solved

how to remove drop down values while adding

Posted on 2014-11-11
8
210 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
[X]
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
  • 4
  • 3
8 Comments
 
LVL 9

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 9

Expert Comment

by:Mukesh Yadav
ID: 40436814
On form's onBeforeSubmit event check for select Head Value if found remove those heads.
0
Independent Software Vendors: 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 9

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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…

705 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