Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

javascript, button, count

I have below dropdown and if I select 1 or 2, it will loop a set of

<input type=text name=firstName1><input type=text name=lastName1>
or
<input type=text name=firstName1><input type=text name=lastName1>
<input type=text name=firstName2><input type=text name=lastName2>
<button>Remote</button>

and if remote button is clicked, it will remove the select row.

How can I do that?

 <div class="form-group input-group">
                                            <span class="input-group-addon"><i class="fa fa-heart-o"></i></span>                                              
                                                <select required class="form-control" id="primaryKids" name="primaryGender">
                                                  <option value="" disabled="disabled" selected="selected" class="disabled">How Many Kids</option>
                                                                <option value="1">1</option>
                                                                <option value="2">2</option>
                                               </select>
 </div>
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Just a suggestion -- you may be overthinking this.  Most people know how many kids they have and can type the number.  Why not just use a text input control?
	<script >
		function loadPage(){
			var btn = document.getElementsByTagName('button');
			btn[0].addEventListener('click', removeNode);
		}
		document.addEventListener('DOMContentLoaded', loadPage);

		function removeNode(){
			var nodeToRemove = document.getElementsByTagName('select');       
			nodeToRemove[0].remove(nodeToRemove[0].selectedIndex);
		}   
    </script>

Open in new window

Avatar of ITsolutionWizard

ASKER

albacom:<button>Remote</button> the button control's will be dynamically generated, like
id=btn1 btn 2 btn 3....

how can I handle in this case? Thanks
<script >
		function loadPage(){
			var btn = document.getElementsByTagName('button');
            for(var i = 0; i < btn.length; i++){
				btn[i].addEventListener('click', removeNode);
            }
		}
		document.addEventListener('DOMContentLoaded', loadPage);

		function removeNode(){
            alert('Button ' + this.id + 'Clicked');
			var nodeToRemove = document.getElementsByTagName('select');       
			nodeToRemove[0].remove(nodeToRemove[0].selectedIndex);
		}   
    </script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Altin Bardhi
Altin Bardhi
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Your sample work in live webpage.. .Thanks