/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] I can’t find the right way to get a form field value

Hi

I’m trying to get a form field value into a function and I’m not doing it right because it isn’t working

here’s the relevant code from the page :

[CODE]
<form action=”produits-frais-infos.php” name=”clientcoord” method=”post” onSubmit=”return checkrequired(this,’message’)”>
<input type=”radio” name=”deltype” value=”livr””.$check.”>
[/CODE]

and the js function:

[CODE]function checkrequired(which, txt){
var radioButt = “”;
radioButt = which[“deltype”].value;
alert(“value = ” + radioButt);
//if(radioButt=”altadresse”){
var pass=true;

for (i=0;i<which.length;i++){
var tempobj=which.elements[i];
if (tempobj.name.substring(0,2)==”r_”){
if (((tempobj.type==”text”||tempobj.type==”textarea”||tempobj.type==”select-one”)&&tempobj.value==”)||(tempobj.type.toString().charAt(0)==”s”&&tempobj.selectedIndex==-1)){
pass=false;
break;
}
}
}
if (!pass){
alert(“Champ(s) obligatoire(s) : ” + txt + ” ! n Veuillez vérifier le(s) champ(s)”);
return false;
}else{
return true
}
//}else{
// return true
//}
}[/CODE]

I would just like to get the value of “deltype” radio button into the function but it’s not happening

can anyone suggest what i’m doing wrong here ?

thanks

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisNov 13.2007 — The "value" of a radio button never changes in the web page, only in the submission. You probably want to look at the "checked" state.

Also, you probably need to change the html a bit. I don't think you need the quotes, or they should be part of the server variable $check.
Copy linkTweet thisAlerts:
@steamPunkauthorNov 13.2007 — yes $check is php var - all the other quotes had slashes

when you say i need to look at the "checked" state - how would i do that ? Can i test for it in my function ?
Copy linkTweet thisAlerts:
@gil_davisNov 13.2007 — radioButt = which["deltype"].checked;The result is True or False. If you don't want to change your compare logic, you can do this:
radioButt = (which["deltype"].checked) ? which["deltype"].value : "";
Copy linkTweet thisAlerts:
@steamPunkauthorNov 13.2007 — ok thanks

?
×

Success!

Help @steamPunk 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.18,
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,
)...