0

I have this java script code which is call on page page by jquery

 <script> 
  function initReportExplr() {
    alert(jQuery('#inputValues').val());

  }
  $(document).ready(function() {
    initReportExplr();
  });
  </script>

and this is component i am using

<h:inputText id="inputValues" value="#{reportsBean.birtServerInformation}"/>

and inside get method i am initializing variable

public String getBirtServerInformation() {
        StringBuilder birtInfo = new StringBuilder();
        birtInfo.append(Constants.BIRT_SERVER_URL);
        birtInfo.append(",");
        birtInfo.append(Constants.BIRT_SERVER_PORT);
        birtInfo.append(",");
        birtInfo.append(Constants.BIRT_USER_NAME);
        birtInfo.append(",");
        birtInfo.append(Constants.BIRT_PASSWORD);
        birtServerInformation = birtInfo.toString();
        return birtServerInformation;
    }

But i am getting undefined when trying to print the value by this code alert(jQuery('#inputValues').val());

Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
  • 1
    What do you see when you do only `jQuery('#inputValues')`? And don't use `alert()` for debugging, use `console.log()` and see logs in `F12` console. If your `` is inside `` then id contains also naming container id. Use inspect on this field and check client ID, then it should work. – Geinmachi Sep 30 '15 at 17:01
  • @Geinmachi I am getting `Syntax error, unrecognized expression: unsupported pseudo: reportsForm1` tried this code `jQuery('#contentform:reportsForm1:inputValues') ;` – Subodh Joshi Sep 30 '15 at 17:38
  • You have to escape `:` with \\, so `jQuery('#contentform\\:reportsForm1\\:inputValues').val()` – Geinmachi Sep 30 '15 at 17:39
  • @Geinmachi now i tried with this ` var myArray = document.getElementById("contentform:reportsForm1:inputValues").value;` this is giving proper values – Subodh Joshi Sep 30 '15 at 17:43
  • Look my previous comment – Geinmachi Sep 30 '15 at 17:44
  • @Geinmachi That is giving same exception – Subodh Joshi Sep 30 '15 at 18:13
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/91023/discussion-between-subodh-joshi-and-geinmachi). – Subodh Joshi Sep 30 '15 at 18:18

1 Answers1

0

As mentioned by @Geinmachi one solution of this by jquery is

jQuery('#contentform\\:reportsForm1\\:inputValues').val();

and another way through JavaScript is

document.getElementById("contentform:reportsForm1:inputValues").value;
Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202