/    Sign up×
Community /Pin to ProfileBookmark

how to pass a parameter through documetn.form.actoin ..?

hi friends,
i have 3 buttons ‘add’,’update,’delete’ in my jsp what i want is depending on the button name i am trying to do the actoin.

Below i have given my function —–> field i will get my “Button Name”…

My question is how can i send a button name just like a parameter to servlet?
like for ex:
“../Customer?field.name” <——— is this possible i am getting error is any other ways?

[Code]
function CustAction(field){
var name=field.name;
var FieldName = document.forms[0].PassportNo.value;
document.forms[0].method=”Post”;
document.forms[0].action=”../Customer”;
document.forms[0].submit();
}
[/code]

any kind of help is greatful.
Ajay.

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@gpm1982Nov 20.2007 — The correct URL with parameters is:
../Customer?field=value

you can even include this parameter into the function as follows:
function CustAction(field){
var name=field.name;
var FieldName = document.forms[0].PassportNo.value;
document.forms[0].method="Post";
document.forms[0].action="../Customer?field=value";
document.forms[0].submit();
}
Copy linkTweet thisAlerts:
@msg2ajayauthorNov 20.2007 — --->?

document.forms[0].action="../Customer?field=value";

is it field.value of field=value... because there is no "value" defined...
Copy linkTweet thisAlerts:
@msg2ajayauthorNov 20.2007 — hi i have tried like below

document.forms[0].action="../Customer?bname='"+fname+"'";

but i am getting the value with in '<value>'...ex: 'Add'.....
Copy linkTweet thisAlerts:
@gpm1982Nov 20.2007 — oops sorry, my bad. for that, you need to edit the function code:
function CustAction(field){
var name=field.name;
var FieldName = document.forms[0].PassportNo.value;
document.forms[0].method="Post";
document.forms[0].action="../Customer?"+field.name; // edit this line
document.forms[0].submit();
}


I'm not sure if it's field.name or field.text

Test both and see which one works ?
Copy linkTweet thisAlerts:
@msg2ajayauthorNov 21.2007 — thanQ very much gpm for quick reply i will try...
Copy linkTweet thisAlerts:
@msg2ajayauthorNov 21.2007 — hi,

I have tried both but not working any how thanQ for quick reply.
Copy linkTweet thisAlerts:
@msg2ajayauthorNov 21.2007 — ThanQ Acoder
Copy linkTweet thisAlerts:
@gpm1982Nov 23.2007 — basically, if the field is in the form, then the servlet can get the field automatically. There's no need to include it as a parameter in the action property. eg.

[code=html]<form method="post" action="Customer">
Username: <input type="text" name="txtUsername" />
<input type="submit" value="Submit" />
</form>[/code]


and on the server side (for this example, I use PHP):
[code=php]<?php
if( isset($_POST['txtUsername']) ){
// commands
}
else{
echo "No params found...";
}
?>[/code]
×

Success!

Help @msg2ajay spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...