on 07-05-2005 4:07 PM
Hi,
I am tring to access an HTMLB controll (InputField) from JavaScript, but having some problems...
I have created a DynPage and created an InputField: InputField inField = new InputField("inField");
Now, in the javascripts I am trying to access this InputField text with:
var txt = document.form.inField.value
but it does not work... I get a JavaScript error.
Any suggestion how to access the InputField from the JS? maybe with getElementByid?
Thanks in advance,
Aviad
Hi Aviad,
The reason for the error is that the actual html id of an htmlb component is not the id you give it in the c'tor.
You can get the "real" id using:
this.getPageContext().setCurrentForm(myForm);
String id = this.getPageContext().getParamIdForComponent(inField);
Then, in the javascript use this id the same way you tried to use "inField":
form.addRawText("var txt = document.form."+id+".value;");
If that doesn't work try:
form.addRawText("var txt = document.getElementById('"+id+"').value;");
Hope that helps,
Yoav.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you need to do the following.
function validateField()
{
var funcName = htmlb_formid+"_getHtmlbElementId";
func = window[funcName];
var inputfield = eval(func("fname_input"));
var inputString = inputfield.getValue().toString();
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Aviad,
Htmlb controls are not a direct reprsentation of html controls. The way to get hold of them is by following lines.
function validateField()
{
//htmlb_formid : this is automatically generated
//the following lines will get you the javascript function
//name to call to get hold of your input field
var funcName = htmlb_formid+"_getHtmlbElementId";
func = window[funcName];
//The funtion is called with id of the input field
//which returns the htmlb control object
var inputfield = eval(func("fname_input"));
//this will get you the value of inputfield
var inputString = inputfield.getValue().toString();
}
<b>Note: Make sure you set jsObjectNeeded = true for the htmlb control.</b>
PS: Please consider rewarding points for helpful answer. thank you.
Message was edited by: Prakash Singh
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.