Skip to Content
author's profile photo Former Member
Former Member

JavaScript updating htmlb component value

Hello all,

I'm not a JavaScript guy atall and need some help.

I'm writing a Java DynPage iView in EP6 (not a JSPDynPage).

Can we update the value shown in an InputField from JavaScript? What I mean is, we have defined an input field and we can obviously now write

<code>

myInputField.setString("Hello");

</code>

but I want to do this from JavaScript (I do have a reason, I'm leaving it out for simplicities sake).

So I would write a JavaScript function, added to the form object as raw text....

<code>

myForm.addRawText("<script>function myFunc(){

//How can I update the input field from here?

}</script>");

</code>

If you have any ideas, or if you know that I can't do this then I'd be glad to hear from you.

Thanks,

Patrick.

Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • Best Answer
    Posted on Jan 31, 2005 at 02:43 PM

    For InputField you will need to use jsObjectNeeded="true"

    Then add a Client side event (or leave this out if you dont this event) by doing

    inputFieldID.setClientEvent(com.sapportals.htmlb.enum.EventTrigger.ON_CHANGE,"javascriptFunction()");

    Then get the HTMLB inputfield ID

    <%
    String inputField =myContext.getParamIdForComponent(inputFieldID);
    %>

    You can use the eval(inputField) in javascript code to work with the control ( .setValue() in javascript will set the value for the inputfield ).

    hth

    Sid

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 31, 2005 at 03:46 PM

    Hi Patrick,

    If you would like to set a field via javascript, you will need to know the field name (in your case myInputField).

    Assigning values in Javascript is easy:

    document.forms[0].myInputField.value = 'your new text goes here';

    document is referring to your current screen. forms[0] is an entry in the forms list (first form in this case). Can be replaced with forms["myFormHasAName"].

    Please note this .value property is only available at client side. So no communication with the server.

    The above explains a standard Javascript solution for it. However you are mentioning you are using a Java Page. Did you mix it up with javascript? No worries then, the solution might be given by Siddhartha (above).

    cheers,

    Noel

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 01, 2005 at 08:33 AM

    Hello folks,

    Noel, it's a dynpage iView written in Java that I can add some JavaScript to with

    <code>

    myForm.addRawText("JavaScript");

    </code>

    not an html page with JavaScript. So the input filed is an HTMLB InputField object not an HTML input field.

    Siddhartha, you mentioned using jsObjectNeeded, how is this used? The layout is not built in a JSP, I am not using a JSPDynPage... I'm using a DynPage and building the interface from java.

    The actual problem is this. We have an iView that allows users to enter parameters, click 'Execute' and a client side event forces a couple of iViews to do something with those input parameters. No problems.

    One of the input fields is for a parameter 'Station', there are almost 1000 stations in the system so the user can't remember all of these numbers. We have given them the ability to enter part of a station number and click 'Search'. We were opening a popup window displaying a table of all stations that contained the search pattern and then when the user selects a row from the table we wanted to pass the selected station number back to the input field. The problem is that when the popup window is active the portal page with the original iView is not active so regular eventing won't work. That's why I wanted to use JavaScript, in the popup I write something like

    <code>

    window.opener.myFunc(selectedStationNumber);

    </code>

    Having added the JavaScript function myFunc to the original input parameter iView (that opened the popup) this function will then be called. From this function I want to then put the 'selectedStationNumber' into the station number input field.

    What I've done just now is place the iView displaying the stations table on the page instead of in a popup window. This way I can us client side eventing back and forward between the iViews and it works. Using a popup window will make the page tidier I think.

    I suppose one solution (using the popup method) would be to put the selected station number in the HTTP session, call a JavaScript function in the original iView that forces a reload, on reload read from the HTTP session to get the selected station number. This seems quite untidy though. I'd much rather be able to simply pass the selected number straight from the popup to the iView that opened the popup.

    Thanks for your replies, both of you.

    Any more help with this would be great.

    Patrick.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Patrick,

      ok, we've done this about 15 months ago, here comes a proposition:

      We have done it with two components, one component for the popup and one for setting the value / closing the window. Anyhow, the value could be set by the first or by the second component, that does not really matter. If you don't need a server roundtrip at all, all this also could be implemented within one component.

      I'll show the way with two components.

      From your "underlying" page/iView, you press a button which opens a new window / component. Pass the html name of the form and the input field in question, too. Now the popup pops up 😊 the user makes a choice and presses a "Choose this" button. A server roundtrip occurs, saving the value (into a bean) and generates the "Pass value / Close window" page. This could look like this (here given as JSP):

      <jsp:useBean id="SelectionBean" scope="session" class="com.btexx.example.SelectionBean"/>
      <SCRIPT LANGUAGE="JavaScript">
        window.opener.document.<%=SelectionBean.getFormID()%>['<%=SelectionBean.getInputFieldID()%>'].value='<%=SelectionBean.getSelectedValue()%>';
        window.close();
      </SCRIPT>

      Hope it helps

      Detlev

  • author's profile photo Former Member
    Former Member
    Posted on Feb 06, 2005 at 11:01 AM

    Hello all,

    Thanks for all the help.

    I've moved away from that project for the time being so it'll be a whiles before I put your help to the test.

    I've notified our other programmer that is still there about your answers and hopefully he'll try it out.

    Thanks again everyone,

    Patrick.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.