function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
liron169liron169 

Javascript. Value property return undefined

Hello,

 

I'm trying to use JS in visualforce page. The target is when the user input data in specific field - to update this value in input field in a list.

the problem: the value property (from the list) return 'undefied'.

However, if I try to get the InnerHTML and print it I get:

 

<input id="docPage:frm:results:Data&colon;0:j_id39" maxlength="30" name="docPage:frm:results:Data&colon;0:j_id39" size="20" value="1" type="text">

 

so I assume that I refering to the field correctly.

 

Any idea how to solve it?

 

by the way, if I'll update the InnerHTML property than the problem is that field became from InputText to OutputText.

 

<script type="text/javascript">
    function updateAll()
    {
	//Input value from User
        var userInput= document.getElementById('{!$Component.frm.mainblock.massFields.inputSection.inputID}').value;
        
        //list Size
        var listSize = {!blLst.size};
        
        for (i = 0; i < listSize; i++)
        {
            var test = document.getElementById('docPage:frm:results:Data&colon;' + i + ':MTVsID').value;
            alert(test);	//get popup with Undefined
            
        }
    }
</script>

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Avidev9Avidev9
If you are seeing the input tag in the innerHTML I guess you are looking one level up the actual element. You are not actual referencing the input element rather you are pointing to immediate parent of the element.

This is why you are getting error.

All Answers

Avidev9Avidev9
If you are seeing the input tag in the innerHTML I guess you are looking one level up the actual element. You are not actual referencing the input element rather you are pointing to immediate parent of the element.

This is why you are getting error.
This was selected as the best answer
liron169liron169

Thanks, You're right.

I was trying to refer to 1 level up. (to the apex:column tag instead of the inputField inside the apex:column).

 

However, I try now to update the code, but still can't get the value (actually now I cannot get even the innerHTML). I assume it something with syntax.

 

I update the line inside the loop:

 

var test = document.getElementById('docPage:frm:results:Data&colon;' + i + ':MTVsID:MTVsIDInput').value

Avidev9Avidev9
I guess there is something wrong with the syntax.
Why dont you check the id of input element by doing a inspect element of the columns.

This will give you an idea about the Ids
liron169liron169

Great.

You're right again.

 

I should refer to it only with the ID of the inputField (not need the apex:column in the chain)

 

Thanks a lot.

 

var test = document.getElementById('docPage:frm:results:Data&colon;' + i + ':MTVsIDInput').value;