Solved

how to remove drop down values while adding

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

Expert Comment

by:Mukesh Yadav
Comment Utility
Please elaborate your problem...
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
Comment Utility
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 6

Expert Comment

by:Mukesh Yadav
Comment Utility
On form's onBeforeSubmit event check for select Head Value if found remove those heads.
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
Comment Utility
Save button is a image , So when click the image i want to remove that time
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 8

Expert Comment

by:Ahmed Merghani
Comment Utility
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
Comment Utility
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 6

Accepted Solution

by:
Mukesh Yadav earned 500 total points
Comment Utility
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
Comment Utility
thanks Mukesh Yadav... Its not generic thats is the problem . Can you help to make it generic one .
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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)

744 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

17 Experts available now in Live!

Get 1:1 Help Now