Error referencing a Struts-Form element from a JavaScript function.

As shown below, when referencing the form element named 'custRegion', from the JavaScript function, I get an error msg - document.forms[0].custRegion has no properties.
It appears that this form-element, which also is present in the logic tag is not visible - is it because I'm referencing it incorrectly...
<SCRIPT> function setRegion() { var theRegion= 'Western'
document.forms[0].custRegion.value=theRegion; } </SCRIPT>
<logic:iterate id="customer" name="customerForm" property="customers" >
<html:text name="customer" property="custRegion"/>
<html:select name="customer" property="custState" size="1" onchange="setRegion()">
<html:option value="1"> California </html:option>
<html:option value="2"> Arizona </html:option>
</html:select>
</logic:iterate>

Here's a quick example of what may help you. It simply disables the select box and slides in a new text box. Nevertheless, it shows you that you accessed a struts property by name.
struts code:
<html:select property="customerRegion">
        <html:option value="-1">Unknown</html:option>
        <html:option value="0">Western</html:option>
</html:select>
//quick & dirty textbox for testing.  you'll probably want <html:text ... here instead.
<input type="checkbox"
       onclick="disableSelectAddTxt(document.YOUR_FORM['customerRegion'], this.checked)" />
Check box to replace select pull-down  
      <div id="setTBox"></div>javascript:
function disableSelectAddTxt(selectBoxName, disableIt)
    var setTBoxName = selectBoxName;
    //alert('You passed me ' +setTBoxName+ ' and' +disableIt);
    selectBoxName.disabled = disableIt;
    var setTBox = document.getElementById("setTBox");
    if (disableSelect == true) {
        setTBox.innerHTML = "<input type=\"text\" name="+setTBoxName+ "size=\"10\">";
    if (disableSelect == false) {
        setTBox.innerHTML = "";
  hope this helps.

Similar Messages

  • Creating form element from within a component

    Hi all,
    I am trying to create a form element within a component
    function which is then called from a .cfm page which has the cfform
    tags. I keep getting a context validation error for the form
    element tag. Here is some sample code:
    <cfcomponent name="yourComponent">
    <cffunction name="createTag" returntype="string"
    access="public">
    <cfsavecontent variable="returnContent">
    <cfselect name="thisSelect">
    <option value="0">Value 1</option>
    </cfselect>
    </cfsaveconten>
    <cfreturn returnContent>
    </cffunction>
    </cfcomponent>
    And in the .cfm page:
    <cfform>
    <cfinvoke component="yourComponent" method="createTag"
    returnVariable="returnContent"/>
    <cfoutput>#returnContent#</cfoutput>
    </cfform>
    The error occurs in the function and it says the cfselect
    must be within a cfform. I tried the function without the save
    content and just set the output="yes" but the same error occurs.
    Any help appreciated in how to get around this. Just putting
    the code in the .cfm is not an option for this.
    Any help appreciated.
    Jim

    quote:
    Originally posted by:
    jim1234
    Thanks for the reply. Yes, that works. So it looks like it
    has to do with the function call.
    After some further investigation, I found out that a regular
    <select> works, it's just the <cfselect> that does not.
    ColdFusion wants it directly within the <cfform> tag.
    Something does not make sense. If the cfsavecontent worked in
    the cfm file, there is no reason for it not to work in a cfc.
    If you want to persue this, the next troubleshooting step is
    to copy the function to your cfm file and see if it works. I
    suspect that you are trying something simple as a proof of concept.

  • Error: 'incorrect access of a member from const-qualified function'

    Hi all,
    While compiling what seemed to be a straightforward chunk of code I got the following error: 'incorrect access of a member from const-qualified function'
    Unfortunately I can't find a small use case to give here, but the gist is:
    int rval;
    my_class::fill_rval(rval);
    with
    struct my_class { static void fill_rval(int &rval); };
    The calling function is a member of a class, but not const-qualified (and not accessing any members in any case!). The callee is a static member function.
    Does anyone know what this error means? The only thing Google finds is a bug report in FileZilla [1] where they fixed it by creating a local variable rather than manipulating temporaries, but I'm not using any temporaries in the first place.
    [1] http://trac.filezilla-project.org/ticket/1283
    Thanks!
    Ryan

    It may be a compiler bug, however, it's impossible to say without seeing the code, of course.
    If you manage to create a reasonably small compilable (well, except for the error) test case, you can post it here or file a bug though http://bugreport.sun.com/bugreport/

  • How can I call a servlet method from a javascript function

    I want to call l a servlet method from a javascript function.
    Does any one have an example of code.
    Thinks in advance

    Actually, as long as the servlet returns valid javascript, you can indeed "call it" from the client. It will initiate a request and return the result to the browser.
    This example uses Perl, but it could be easily modified to go to a servlet instead.
    Note that it is only supported in DOM browsers (IE6+/NN6+/etc)
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
    <html>
    <head>
    <title> Test server-side JS </title>
    </head>
    <body>
    <script type="text/javascript">
    function checkIt(variable, value)
    var newScript = "cgi-bin/validateJS.cgi?"+variable+"="+value;
    var body = document.getElementsByTagName('body').item(0)
    var scriptTag = document.getElementById('loadScript');
    if(scriptTag) body.removeChild(scriptTag);
    script = document.createElement('script');
    script.src = newScript;
         script.type = 'text/javascript';
         script.id = 'loadScript';
         body.appendChild(script)
    </script>
    <p>Test.</p>
    <form id="f1" action="">
    <input type="text" name="t1" id="t1" onChange="checkIt(this.name, this.value)">
    </body>
    </html>
    validateJS.cgi
    #!/opt/x11r6/bin/perl
    use CGI qw(:all);
    my @valArray = split(/=/,$ENV{QUERY_STRING});
    print "Content-type: text/javascript\n\n";
    # myPass is the password
    $myPass = "foobar";
    if ("$valArray[1]" eq "$myPass")
    print "alert(\"Success!!\")";
    else
    print "alert(\"Failure!!\")";

  • How can I access JSP variables from a JavaScript function in a JSP page?

    Respected sir
    How can I access JSP variables from a JavaScript function in a JSP page?
    Thanx

    You may be get some help from the code below.
    <%
        String str="str";
    %>
    <script>
        function accessVar(){
           var varStr='<%=str%>';
           alert(varStr);// here will diplay 'str'
    </script>

  • Triggering a reRender of a JSF component from a Javascript function

    Hi
    I am using a javascript calendar component(JQuery +JCal) to allow the user to select a date for which they want to see events displayed for. When the user selects the date I was planning on outputting the events in a rich:dataTable or something similar.
    Is there anyway that I can trigger a reRender of the dataTable from the javascript, i.e. when someone selects a particular date I would like to trigger a reRender of the rich:dataTable.
    I know I can do it easily from another JSF component, e.g. if I had a commandLink I could set the reRender property to be the id of the dataTable. But I am wondering can I trigger the reRender of the dataTable from a Javascript function, i.e. can I submit an AJAX request
    Thanks

    If you are using the the Richfaces components then you should look at the a4j:jsFunction component, which is provided by Richfaces.
    Follow the following format using the a4j:jsFunction:
    <a4j:jsFunction name="functionName" reRender="targetCompoentId"/>So in the component that the event should be triggered...like the 'onclick' or 'onmouseover' or whatever the legal event is use the following format:
    onclick="functionName();"Richfaces renders the a4j:jsFunction as a javascript function. The a4j:jsFunction name attibute becomes the name of the javascript function; You just have to remember to add the "()" parenthesis to the end of the function name.
    You could technically call the function also inside a javascript that has page access to the javascript generated from the a4j:jsFunction component.
    Hope this helps!

  • Accessing parent window form elements from a JSP file

    Actually I have a JSP page . It calls a popup function to load another JSP file on the event Onclick of a label. In the JSP file loaded on the popup window, I need to access the form elements of the parent.
    Eg: the Parent has a Textarea named "ta_1" in the form "appl_1".
    Now i cannot access this element in the child JSP page using,
    window.opener.document.ta_1.appl_1.value;
    The window.opener is not defined for this HTML page cos the HTML page was generated as an output of the JSP file.
    Please give a JSP code snippet which accesses the parent form element..

    Actually I have a JSP page . It calls a popup function to load another JSP file on the event Onclick of a label. In the JSP file loaded on the popup window, I need to access the form elements of the parent.
    Eg: the Parent has a Textarea named "ta_1" in the form "appl_1".
    Now i cannot access this element in the child JSP page using,
    window.opener.document.ta_1.appl_1.value;
    The window.opener is not defined for this HTML page cos the HTML page was generated as an output of the JSP file.
    Please give a JSP code snippet which accesses the parent form element..

  • How to set a form element value using javascript?

    Hello,
    I have been using the following two functions in AS 9.0.2 to set form values in javascript and it works correctly. However, the same code does not work in AS 10.1.2.0.2. Would appreciate if someone could let me know how to set form elements using Javascript(onchange of a field).
    function set_item_value(p_field_name, p_value)
    var v_index, v_full_name;
    for(v_index=0; v_index<document.forms[0].length; v_index++)
    v_full_name = document.forms[0].elements[v_index].name.split
    if (v_full_name[2] == p_field_name)
    document.forms[0].elements[v_index].value = p_value;
    function get_item_value(p_field_name)
    var v_index, v_full_name, v_return="";
    for(v_index=0; v_index<document.forms[0].length; v_index++)
    v_full_name = document.forms[0].elements[v_index].name.split
    if(v_full_name[2] == p_field_name)
    if(document.forms[0].elements[v_index].type != "radio")
    v_return = document.forms[0].elements[v_index].value;
    else
    if(document.forms[0].elements[v_index].checked)
    v_return = document.forms[0].elements[v_index].value;
    if(v_return == " ")
    v_return = "";
    return v_return;
    Thanks
    Dev

    This is not the best way to write JavaScript in Portal environment!
    You can't be sure that a form is the first in the html source!
    In Portal you change the order of your portlets, and also you can have several instances of the same portlet on the same page!!!
    You should use qualified form and field names!
    Please check the following JPDK methods:
    UrlUtils.htmlFormName
    HttpPortletRendererUtil.portletParameter

  • Form elements generated by javascript seem to crash page processing

    Is there any workaround? I'm asking because I'm trying to use reCAPTCHA and the standard way to do that is to include javascript that outputs the CAPTCHA images and input fields: see http://recaptcha.net/apidocs/captcha/client.html
    If you try to use the noscript version with the input fields properly defined as ApEx page items, the reCAPTCHA code says that you can't do that when you actually have javascript enabled.
    So, anybody know how to make page processing tolerate form elements that haven't been defined as items, or some other way to use reCAPTCHA?

    http://www.inside-oracle-apex.com/adding-captcha-to-your-oracle-apex-application/

  • JRE7 Update 13 blocking java applet from calling javascript functions

    Hi there,
    I'm having a problem where I have a javascript web app that launches an applet that communicates back to the javascript via invoking javascipt methods. It uses the method call from netscape.javascript.JSObject to achieve this. Pre JRE7 Update 13, everything worked fine, but now whenever I try to call a javascript method, it throws a netscape.javascript.JSException: No such method "..." on JavaScript object . This happens only on Firefox and Chrome; however it still works fine in Internet Explorer. Are there some new security settings in JRE7u13 that need to be addressed in order to allow javascript method calling, or is it a Java/Firefox/Chrome bug?
    Thank you for any help!

    I've filed a bug https://bugzilla.mozilla.org/show_bug.cgi?id=839967 but I'm having problems reproducing it in a testcase...everything works. Quite baffling, our application that had worked and still works with other browsers and with an old version of firefox (12) stopped working with the Java 7 update 13.

  • Error while testing the Webservice created from RFC enabled function module

    Our client has provided the SAP WSDL URL and We tried to generate stub using AXIS 2 tool from this SAP WSDL URL and got u201Cservice and binding tagu201D missing error.
    It seems that clients SAP wsdl file is having only web service interface information and does not have Access Description i.e service and binding tag information . 
    Is it mandatory to have service and binding tag in SAP wsdl to consume webservice from third party java application ?
    Could you please let us know how to resolve this error?
    <urgency removed by moderator>.
    Thanks ,
    Ranjit
    Edited by: Thomas Zloch on Mar 25, 2011 1:16 PM

    Hi,
    I think you might have received wrong WSDL.
    In transaction SOAMANGER for a WebService you can select:
    Porttype WSDL document
    or
    WSDL document for selected binding or service -> for a concrete binding
    You need to get the second one which contains service and binding information. The first one is just interface description.

  • Losing form elements and referer when opening in a javascript window

    I am submitting from a.cfm to b.cfm. b.cfm opens in a Javascript window. In b.cfm, the form elements from a.cfm are lost and cgi.referer returns nothing.
    When I don't open b.cfm in a Javascript window, everything is ok.
    What is this happening?

    Still getting the same thing.
    When sf is clicked in aaaa.cfm, bbbb.cfm does not see the variable named "a".
    When the link with the * is clicked, bbbb.cfm sees "a".
    What on earth am I doing wrong?
    This is aaaa.cfm.
    <html>
       <head>
          <script language="javascript">
             function f(nextpg_,nextwin_)
                var _attrs='';
                var _br=navigator.appName;
                document.forms[0].method="post";
                document.forms[0].action=nextpg_;
                if (_br=='Microsoft Internet Explorer')
                    _attrs='height='+screen.height+',width='+screen.width+'toolbar=0,menubar=0';
                    _attrs=_attrs+'top=0,left=0';
                    window.opener=null;
                    window.close();
                    window.open(nextpg_,nextwin_,_attrs)
                else
                  alert('Internet Explorer Please.')
             function g(nextpg_,nextwin_,val)
                var _attrs='';
                var _br=navigator.appName;
                document.forms[0].method="post";
                document.forms[0].action=nextpg_;
                if (_br=='Microsoft Internet Explorer')
                    _attrs='height='+screen.height+',width='+screen.width+'toolbar=0,menubar=0';
                    _attrs=_attrs+'top=0,left=0';
                    window.opener=null;
                    window.close();
                    window.open(nextpg_+'?a='+val,nextwin_,_attrs)
                else
                  alert('Internet Explorer Please.')
          </script>
          <title>
          </title>
       </head>
       <body>
          <form name="ff">
             <cfset a=0>
             <cfoutput>
                <input name="a" type="text" value="#a#">
             </cfoutput>
             <input name="sf" type="submit" value="*" onClick="f('bbbb.cfm','windowname')">
             <a href="javascript:g('bbbb.cfm','x','<cfoutput>#a#</cfoutput>')">
             </a>
          </form>
       </body>
    </html>
    This is bbbb.cfm
    <html>
       <head>
          <title>
          </title>
       </head>
       <body>
          <cfoutput>
             *#a#*#now()#*
          </cfoutput>
       </body>
    </html>

  • Javascript function is not working for jsp:include.. form elements

    HI,
    I have two jsp's and i will include one jsp in the another jsp, when i do this
    i am not able to access child form elements value using javascript. the javascript
    function is defined in the main jsp. but i could able to get the main form elements
    through javascript
    here is the code.
    main.jsp
    <!--Generated by WebLogic Workshop-->
    <%@ page language="java" contentType="text/html;charset=UTF-8"%>
    <%@ taglib uri="netui-tags-databinding.tld" prefix="netui-data"%>
    <%@ taglib uri="netui-tags-html.tld" prefix="netui"%>
    <%@ taglib uri="netui-tags-template.tld" prefix="netui-template"%>
    <netui:html>
    <head>
    <title>
    Web Application Page
    </title>
    <script language="JavaScript">
    function isValidAge() {
    alert ("hage " +document[getNetuiTagName("MyForm")][getNetuiTagName("age")].value)
    alert ("swage " +document[getNetuiTagName("MyForm")][getNetuiTagName("swage")].value)
    alert ("wage "+document[getNetuiTagName("MyForm")][getNetuiTagName("wage")].value)
    </script>
    </head>
    <body>
    <p>
    <netui:form action="myaction" tagId="MyForm">
    <netui:textBox tagId="age" dataSource="{actionForm.age}"/>
    <netui:textBox tagId="swage" dataSource="{actionForm.swage}"/>
    here i am adding
    <jsp:include page="NewPage.jsp" />
    <netui:button onClick="isValidAge();" />
    </netui:form>
    </p>
    </body>
    </netui:html>
    child.jsp :
    <!--Generated by WebLogic Workshop-->
    <%@ taglib uri="netui-tags-html.tld" prefix="netui"%>
    <table class="tablebody">
    <tr class="tablebody">
    <td> wife age
    <netui:textBox tagId="wage" dataSource="{actionForm.wage}"/>
    </td>
    </tr>
    </table>
    can you tell me is this is bug in hte weblogic portal SP1.
    I am using weblogic portal SP1.
    thanks in advance
    shashi

    in this part:
    if(document.LForm.uname.value==null || document.LForm.upassword.value==null)should be:
    if(document.LForm.uname.value=="" || document.LForm.upassword.value=="")or
    if(document.LForm.uname.value.length==0 || document.LForm.upassword.value.length==0)

  • Retrieving form components added via javascript

    I looked around and couldn't find anything on this. I'm adding form elements dynamically using Javascript. How do I read those dynamically added elements? Faces doesn't pick them up and they're not coming through in the request attributes (HttpServletRequest#getAttribute(String)). Anybody know how this works or knows of a resource? Any help would be appreciated.

    You should look in the request parameter map, not the request attributes map. See ExternalContext.getRequestParameterMap() or use the JSF-reserved keyword param in your EL.

  • Calling Javascript function from PL/SQL Page Process

    Hi All,
    So far I have seen many threads that answered the question: Calling a PL/SQL from a Javascript function. I would like to know if it's posiible to do the reverse process as follows:
    DECLARE
       v_name APPLICANTS.NAME%Type;
       v_surname APPLICANTS.SURNAME%Type;
       v_idNumber APPLICANTS.ID_NUMBER%Type;
    BEGIN
       select name, surname
       into v_name, v_surname
       from APPLICANTS
       where id_number = :P2_ID_NUMBER;
       //Javascript function call Syntax is what i'd like find out
       onchange="javascript:show_Name(v_name,v_surname);";
    EXCEPTION
       WHEN OTHERS
       THEN
       onchange="javascript:show_Exception(v_name,v_surname);";
    END;& Javascript function to shiow applicant's details is:
    function show_Name(item1,item2){
       alert('Applicant's Name is: '  + item1 + ' & Surname is: ' + item2);
    }THANK YOU!
    Regards
    Kamo

    Hi Dinesh, Thanks for the response!
    I've also tried doing the following without success:
    DECLARE
       v_name APPLICANTS.NAME%Type;
       v_surname APPLICANTS.SURNAME%Type;
       v_idNumber APPLICANTS.ID_NUMBER%Type;
    BEGIN
       select name, surname
       into v_name, v_surname
       from APPLICANTS
       where id_number = :P2_ID_NUMBER;
       htp.p('<script type="text/javascript">');
       htp.p('
                alert('Applicant's Name is: '  + v_name + ' & Surname is: ' + v_surname);
       htp.p('</script>');
    EXCEPTION
       WHEN OTHERS
       THEN
       htp.p('<script type="text/javascript">');
       htp.p('
             alert('Exception.');
       htp.p('</script>');;
    END;Do you know why this is not working?
    Regards
    Kamo

Maybe you are looking for