Link to home
Create AccountLog in
Avatar of Rouchie
RouchieFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Enhance function to copy values to fields AFTER current field

The following function copies values from a text box to all text boxes on the page that have a particular ID value.  It works well, but I was wondering if it was possible to enhance the logic so that instead of copying the value to ALL textboxes that match the given ID value, to just copy values to all matching text boxes that appear in the DOM after startBox?

function CopyValues(startBox){
		var startboxid = '#' + startBox;
		var level = $(startboxid).val();
		$("input[type='text'][id$='txt_Level']").each(function(){
			if ($(this).val()=='') {
					$(this).val(level);
			}
		});
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Rouchie

ASKER

Okay thanks.  How do I read the index value of an element relative to the entire DOM rather than a parent element?  The examples shown seem to read the index value of a list item relative to the list, rather than the entire DOM.

Thanks
Avatar of Rouchie

ASKER

I think I've figured it out.. Can you please advise that this is correct...

var startIndex = $("#myElementID").index('*');

Open in new window

Yes, it seems correct.
Did you tried the same? does it give correct output?
Avatar of Rouchie

ASKER

Yes it works thank you.