Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

this.form.name is coming  as an object????????????????

Posted on 2006-04-02
31
Medium Priority
?
221 Views
Last Modified: 2010-04-01
Hi
I am using exaclty

onchange="updateName('attrName','attributeType',this.form.action,this.form.name);">

and my produced HTML select object is in a page section which is enclosed by a <form> and </form> tag.

I am getting this.form.name as an object. i have verified it using alert in my js script.
The this.form.name should be a string..

do i need to have a "name" in following line
<html:form action="/POIAddAttribute.do" method="POST">
?????

its urget,,,,,,,please help?

Thanks in advance

regards,
venkat
0
Comment
Question by:ramareddyj
  • 14
  • 11
  • 3
28 Comments
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16358011
i think it must be onchange="updateName('attrName','attributeType',this.form.action,this.form.name.value);"

please check & tell.
0
 

Author Comment

by:ramareddyj
ID: 16358082
Hi
i tried and it shows the form name is "MAUI ORIENTAL MARKET"
(I have put in alert in my js script which shows this value.)

i have no idea what is it???

regards,
venkat
0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16358099
tell me something what does your updateName function expects as parameteres & what are you trying to do.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:ramareddyj
ID: 16358101
Actually i am trying to send form........the action is captured from the action defined in
<html:form action="/POIAddAttribute.do" method="POST">

but from where will i get teh name of the form???
thats the problem......i need the form beacuse i need to refresh the page using a java script which takes form as an input

Regards,
venkat
0
 

Author Comment

by:ramareddyj
ID: 16358106
my js function is like this


function updateName(name,attributeType,FormAction,FormName)
      {
            alert("1= " + FormAction + "-form name is 2 =" + FormName);
            var attribute = document.forms[1].elements[attributeType];
            if(attribute.selectedIndex >= 0){
                  addrValue = attribute.options[attribute.selectedIndex].innerText;
                  var nameAttribute = document.forms[1].elements[name];
                  nameAttribute.value=addrValue;
            
                  //return false;      
            }
            alert("form action  222222is " + FormAction + "formname is " + FormName);
            document.forms[FormName].action=FormAction;
            alert("form action  666666666666666666s " + FormAction + "formname is " + FormName);
            document.forms[FormName].submit();
            
        

      }
0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16358130
i think you need to have name attribute in your form defination.

<html:form action="/POIAddAttribute.do" method="POST" name = "FormName">
0
 
LVL 11

Expert Comment

by:fargo
ID: 16358132
Hi,

I don't see the point of using formName and formAction in the javascript u used. If i understood you correctly, you are using one form. Correct??
As you are submitting the same form, why to get the action and submit it??

function updateName(name,attributeType)
     {
          var attribute = document.forms[1].elements[attributeType];
          if(attribute.selectedIndex >= 0){
               addrValue = attribute.options[attribute.selectedIndex].innerText;
               var nameAttribute = document.forms[1].elements[name];
               nameAttribute.value=addrValue;
         
               //return false;    
          }
          document.forms[1].submit();
     }

fargo
0
 

Author Comment

by:ramareddyj
ID: 16358174
hey thanks a lot....i got my mistake.......

One another request to u sirr.....

the value which i am selecting from my dropdown (on selection the above function is getting called) ..can i get that value once the page is refreshed.....

regards,
venkat


0
 

Author Comment

by:ramareddyj
ID: 16358178
actually i am using this line to fetch the value of teh drop down value(selected value)

String attributeType= (String)pageContext.getAttribute("attributeType");

once the page is refreshed can i get this value??????????

regards,
venkat
0
 
LVL 11

Expert Comment

by:fargo
ID: 16358212
Hi,

when the form is submitted, the attribute value from the drop down box is also getting submitted [selected one].  

If it suits, Keep the page form in session and you need not to worry then. Otherwise pass the attribute value again back to the page from the action and handling remains same.

fargo
0
 

Author Comment

by:ramareddyj
ID: 16358357
will   String attributeType= (String)pageContext.getAttribute("attributeType"); not give me the value of the selected item of the drop down.???
0
 
LVL 11

Expert Comment

by:fargo
ID: 16358369
No. pageContext.getAttribute() has nothing to do with your form.

fargo
0
 

Author Comment

by:ramareddyj
ID: 16358386
when the page is refreshed the action class is not called........how will sending value form the action class help me???

if it is possible then how should i go abt it???


Thanks a lot in advance sirr..
regards,
venkat
0
 
LVL 11

Accepted Solution

by:
fargo earned 2000 total points
ID: 16358418
Hi,

What do u mean when the page is refreshed the action class is not called? If the form is submitted and the action of the form is pointed to the action class, it should be called. Untill unless u have some validation over the form!

Moreover, when u do the refresh or a roundtrip make sure to handle it in action class. What i generally do is to make use of a hidden parameter like follows

<html:form...>
<html:hidden property="action" value="save">
..
</html:form>

When one call a update function with javascript, set this action parameter to say "refresh" like the following

documents.forms[0].action.value="refresh";
documents.forms[0].submit();

In the action class, check if the action value is "refresh". If yes, send it back to the input page. This way, u achieve refresh and flow is kept as clean as possible.

fargo
0
 

Author Comment

by:ramareddyj
ID: 16358955
i got your point.........and i take my words back which said that "when the page is refreshed the action class is not called"
I am through sirr........

actually i was confused ebcause my jsp contains two actions wchih gets called at two diffeten points.
so a bit confusion was there .

but now i have understood teh concept.

Thanks a lot for your help.
Venkat

0
 
LVL 11

Expert Comment

by:fargo
ID: 16358969
No problem. good that u got the point clear.

regards,
fargo
0
 

Author Comment

by:ramareddyj
ID: 16383128
hey,

My requirement is bit changed ...now i am setting the action for drop down change in action class as

String dropDownChangeAction ="updateName(this.form,'" + attributeType+" ','" + actionDropDown+"')";

and now its giving me the same js error that document.forms[] is null or an object

please help..

regards,
venkat
0
 
LVL 11

Expert Comment

by:fargo
ID: 16384768
just a small cross check, i saw in your code

'" + attributeType+" ' // there is a space after attributeType string..check that!
0
 

Author Comment

by:ramareddyj
ID: 16389159
Hi ,
i am calling setting this action in action class.

but it is taking a parameter(the value of the selected item of the drop down) as input.

in my jsp  i am using
onchange='<%=dropDownChangeAction%>'>


String dropDownChangeAction ="updateName(this.form,'" + attributeType+" ','" + actionDropDown+"')";

the problem is that i am taking attribute calue in action class but that shold come from drop down at run time......

please show me way out

regards,
venkat
 
0
 

Author Comment

by:ramareddyj
ID: 16389203


my js function is

function updateName(name,attributeType,FormAction)
      {
                  
            alert("the form is "+ name);
            var nameObj = name.nameType;
            index = nameObj.selectedIndex;
            if(index >= 0)
            {
                  nameObjValue = nameObj.options(index).value;
                  //name.nameType.value=nameObjValue;

                  var nameAttribute = document.forms[1].elements[name];
                  nameAttribute.value = nameObjValue
                                 }
                                        a lert("form action  222222is " + FormAction + "formname is " + name);
            //document.forms[1].action=FormAction;
            document.forms[1].submit();


the error it is giving is selectedindex is null or an object

regards,
venkat
0
 
LVL 11

Expert Comment

by:fargo
ID: 16390012
Hi,

Some of your code is not clear to me like the following:

what is nameType?
What u r trying to do here  var nameAttribute = document.forms[1].elements[name];

So, as far as i understand, the following piece of code will help u.. Copy the below code in a html page...and check it..

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function updateName(formname,attributeType,FormAction)
     {
               
          alert("the form is "+ formname.name);
          var nameObj = document.forms[0].elements[attributeType];
          alert("the nameObj is "+ nameObj);
              var index = nameObj.selectedIndex;
            alert("the index is "+ index);
              if(index >= 0)
          {
               nameObjValue = nameObj.options(index).value;

               var nameAttribute = document.forms[0].elements['newname'];
                 alert("the check is "+ document.forms[0].elements['newname']);
               nameAttribute.value = nameObjValue
                 alert("the check is "+ document.forms[0].elements['newname'].value);
              }
          alert("form action  222222is " + FormAction + "formname is " + name);
              document.forms[0].action=FormAction;
              document.forms[0].submit();
      }

      function getSelected( selectbox ) {
            for (i=0;i<selectbox.length;i++)
                  if (selectbox.options[i].selected) {
                        return selectbox.options[i];
                  }
      }

</script>
</HEAD>
<BODY>

<form name="actionForm" action="">
<input type="hidden" name="newname">
<select name="attributeList" id="attributeListId" onchange="updateName(this.form, 'attributeList','actionToActionClass');">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
<option value="E">E</option>
</select>

</form>

</BODY>
</HTML>


0
 

Author Comment

by:ramareddyj
ID: 16390394
hi

String dropDownChangeAction ="updateName(this.form," + actionDropDown + ")";

in my jsp if i do view source i am getting folowing line

<select name="attributeType" onchange="updateName(this.form,/POIExtDropDownChange.do)">-new-
<option value=" "> </option>

at this line it is giving js error as  : "/" expected

what is the issue??

regards,
venkat

0
 
LVL 11

Expert Comment

by:fargo
ID: 16390432
String dropDownChangeAction ="updateName(this.form," + actionDropDown + ")"; // You are missing the '
TO
String dropDownChangeAction ="updateName(this.form,'"+actionDropDown+"')";

0
 

Author Comment

by:ramareddyj
ID: 16390590
hey now i am in another problem.............

i have jsp which shows a  link.
on clicking this link another form is dipalyed on the screen on one of the corner.

now in the form which is in the corner i have a combo box. on selecting anything in the combo i an calling my update function which inturn calls an action class....

since i a using struts framework so i need to mention the <forward > tad in struts-config.xml.

so what should i set the forward tag.

i have tried setting the jsp of the overall page.
i have tried the action of the overall paeg
i have tried the action whcih is called on clicking the link

regards,
venkat


0
 
LVL 11

Expert Comment

by:fargo
ID: 16390657
the forward should be for "Action which causes the load of the original or overall page"
0
 

Author Comment

by:ramareddyj
ID: 16390865
but in that case it will not show the corner form.
0
 
LVL 11

Expert Comment

by:fargo
ID: 16390918
you have to handle the show corner form with setting some parameter in the action class.
0
 
LVL 11

Expert Comment

by:fargo
ID: 16761890
here i have objection. I believe, i replied him as required. Points should be awarded to me.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this step by step method when setting up QuickBooks Online. They will allow you to explore the various features of the advanced settings available to you.
Often, the users face difficulty in accessing Outlook 2016 PST files on Windows 10 computer. One of the reasons behind it is the improper functioning of MS Outlook when the user tries to open it. MS Outlook suddenly stops working, or it will not op…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question