JOHND
JOHND

Reputation: 2767

How to pass Object to controller using javascript

I am having one modelform

public class ABC
{
private String a;

private String b;

private Obj obj;

...getteres and setters.....
}

in my jsp my OnSubmit function is

function showMethod(rowid) 
{
    document.diamondSingleStoneLabForm.action = adminUrl + "/act.htm";
    document.diamondSingleStoneLabForm.suid.value =value1;
        document.diamondSingleStoneLabForm.obj.value = tempObj;

    document.diamondSingleStoneLabForm.submit();
}

now, my question is

How to pass Object to specified action..???

Or How to pass obj.name property value (I cant access it using document.diamondSingleStoneLabForm.obj.name.value = nameVal;)..???

Upvotes: 0

Views: 754

Answers (1)

big zero
big zero

Reputation: 610

Hope in your jsp page you have a text field like this :

<input type="text"  name="obj" value="<%= rs.getString(n)%>" >

but you should tally with the modelform & jsp(this will be your logical part) page where from you fetch the value like <%= rs.getString(n)%>

then you can do this thing

var obj = obj_value;
var action = adminUrl + "/act.htm";  
document.diamondSingleStoneLabForm.action = action ;
document.diamondSingleStoneLabForm.submit(); 

Or you can use: jQuery.post() method in this format

jQuery.post( url [, data] [, success(data, textStatus, jqXHR)] [, dataType] )

you can take a look of this link: jQuery.post()

Upvotes: 2

Related Questions