You need to sign in to do that
Don't have an account?
SFDC_Learner
Need Help with Jquery
<apex:page id="p1">
<!-- <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>-->
<!--<script src="http://code.jquery.com/jquery-1.9.1.js"></script> -->
<apex:includeScript value="{!$Resource.jQueryFile}"/>
<input type="button" value="welcome" id="txt1"/>
<apex:outputText value="hello, good morning" id="txt2" rendered="false"></apex:outputText>
<script>
$(document).ready(function() {
test();
});
$('#txt1').click(function() {
// alert(document.getElementById('txt2').value);
alert('hello');
});
</script>
</apex:page>
Q : Why this statement is showing : Undefined ( // alert(document.getElementById('txt2').value);)
replace alert(document.getElementById('txt2').value);
with
alert(document.getElementById('{!$Component.txt2}').value);
Also, remove rendered="false". With this, the element will never get rendered in the resulting HTML. You can make it hidden if you dont want to display it. But, it should get rendered on the page.
Well when you have imported the awesome JQUERY library, why not to use that to get the value.
The catch is that the ids generate are lil different in VF. They are generally prefixed with some automated generated texts. So you will need the ends with selector to get the value.
Try this
alert($( "[id$='txt2']" ).val( ));
Showing null only .. :)