document.getElementById : how to set value when there is no ID?

andy_dufresne
Tera Expert

I need to set some values from the console in this process I have used something similar on the same form and works great:

document.getElementById("s2id_sp_formfield_subcategory").value = "Car Hire";

The above was a text field.

I have a reference variable and I want to add value similar to above.  The problem is I cannot find the 'ID'.  What options do I have to populate in that text box from console as above?

 

find_real_file.png

17 REPLIES 17

Given a variable of type reference named user, here's what you could do:

[get_element_of_reference('user')]
	.filter(retain_not_null_item)
	.map(get_scope_from_element)
	.filter(retain_not_null_item)
	.map(get_form_from_scope)
	.filter(retain_not_null_item)
	.map(set_value_of('user', NOW.user_id, NOW.user_display_name))

function get_element_of_reference (variable_name) {
	return document.querySelector('[name="' + variable_name + '"][glide-form="getGlideForm()"]');
}

function retain_not_null_item (item) {
	return typeof item != 'undefined' && item != null;
}

function get_scope_from_element (element) {
	return angular.element(element).scope();
}

function get_form_from_scope (scope) {
	return scope.getGlideForm();
}

function set_value_of(field_name, value, displayName) {
	return function (g_form) {
		g_form.setValue(field_name, value, displayName);
	};
}

The script identifies the DOM node that holds the value of a field, references the scope from that node, obtains a g_form element than sets the value of the field.

Community Alums
Not applicable

@János 

 

ANy idea on how to change this to modify the display name of the button and below is the code i have but this is not working.I tried angular.element but couldnt get that working

 

$j("button:contains('Escalate L1')" ).html("Escalate L"+str.result);

@GOwthaman Sorry, but it is only now that I received mail from SN that someone has replied to my post. But I encourage you to open a new thread when you have a question - exactly to avoid this type of problems, plus raise more attention and in this case because your issue - at least on 1st glance, does not seem to be related with the issue at hand and needs a whole lot more details.