/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] after validation posting the form

Hi all,

I am facing a strange problem.I have 2 submit button with onclick event.any one button will work at a single time.Each button is calling a separate function for validation.After the validation is done I want the form to be posted.I am using php as server side.

But after the validation part the form is not submitting.I am not getting the posted values.Here is the code:

[CODE]<script type=”text/javascript”>
function radio_button_checker()
{
var radio_choice = false;
for (counter = 0; counter < f.reply.length; counter++)
{
if (f.reply[counter].checked)
radio_choice = true;
}

if (!radio_choice)
{
alert(“Please select an option.”)
return (false);
}
return (true);
}

function val()
{
if(document.f.treply.value.length == “”)
{
alert(“Please input the answer.”);
return false;
}

}
</script>[/CODE]

[code=html]<form name=”f” method=”post” action=””>

<input type=’text’ name=’treply’ value=”>
<input type=’radio’ name=’reply’ value='<?=$polqr1[‘ans’];?>’>
<input name=”preo” type=”submit” value=”Submit” onclick=”radio_button_checker(f);return false;” />
<input name=”pret” type=”submit” value=”Submit” onclick=”val();return false;” />
</form>[/code]

So both of the submit button is calling separate function.Is it causing any problem in submitting the form values.
Please suggest me what should I do.

Thanks for your co-operation.

Regards,
Raj

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@scragarNov 11.2007 — [code=html]<form name="f" method="post" action="">
<input type='text' name='treply' value=''>
<input type='radio' name='reply' value='<?=$polqr1['ans'];?>'>
<input name="preo" type="submit" value="Submit" onclick="return radio_button_checker(f);" />
<input name="pret" type="submit" value="Submit" onclick="return val();" />
</form>[/code]
your proberly better providing a method for those without javascript though, atm your action is left blank, this is very bad.
Copy linkTweet thisAlerts:
@raj_2006authorNov 11.2007 — your proberly better providing a method for those without javascript though, atm your action is left blank, this is very bad.[/QUOTE]

Sorry m8 i have not understood "atm your action is left blank"

Without javascript i could do it with php but i think here using javascript will be much more better

Regards,

Raj
Copy linkTweet thisAlerts:
@scragarNov 11.2007 — javascript is great as long as the user has it enabled, and their browser supports it. if you cannot do such a thing then it is your duty as the developer to provide an alternate means by which to access the features. by action I meant the action atribute of the form, it doesn't call a validation error on the w3 validator, but according to the documentation it should.
Copy linkTweet thisAlerts:
@raj_2006authorNov 11.2007 — Ya understood now....I think thats why return is used.Is alternative means meant to any other scripting or within javascript I have to use some other method

Its working now ?
Copy linkTweet thisAlerts:
@scragarNov 11.2007 — if you have a server side language then that's perfect, if not then your in a fairly bad position.

the normal method of achiving such things is to use a server side language for final validation, as well as to provide the final effect(adding to DB or whatever).

Javascript should be used to build on this, adding validation user-side so they do not need to reload the page every time they need to validate it. failing to have any server side validation is a terrible idea(javascript is so easy to bypass and manipulate)
Copy linkTweet thisAlerts:
@raj_2006authorNov 12.2007 — Hi

Ya understood now.?

Thanks again for this suggestion.

Regards,

Raj
×

Success!

Help @raj_2006 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.28,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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