Link to home
Start Free TrialLog in
Avatar of ramareddyj
ramareddyj

asked on

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

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
Avatar of Siva Prasanna Kumar
Siva Prasanna Kumar
Flag of India image

i think it must be onchange="updateName('attrName','attributeType',this.form.action,this.form.name.value);"

please check & tell.
Avatar of ramareddyj
ramareddyj

ASKER

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
tell me something what does your updateName function expects as parameteres & what are you trying to do.
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
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();
            
        

      }
i think you need to have name attribute in your form defination.

<html:form action="/POIAddAttribute.do" method="POST" name = "FormName">
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
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


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
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
will   String attributeType= (String)pageContext.getAttribute("attributeType"); not give me the value of the selected item of the drop down.???
No. pageContext.getAttribute() has nothing to do with your form.

fargo
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
ASKER CERTIFIED SOLUTION
Avatar of fargo
fargo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

No problem. good that u got the point clear.

regards,
fargo
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
just a small cross check, i saw in your code

'" + attributeType+" ' // there is a space after attributeType string..check that!
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
 


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
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>


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

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

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


the forward should be for "Action which causes the load of the original or overall page"
but in that case it will not show the corner form.
you have to handle the show corner form with setting some parameter in the action class.
here i have objection. I believe, i replied him as required. Points should be awarded to me.