/    Sign up×
Community /Pin to ProfileBookmark

cannot validate drop down list in form

Newbie java person here.
I’ve used Dreamweaver to validate text fields in a form but it doesn’t seem to work for drop down lists/menus.
I’ve read some tuts on javascript and still can’t really tell why it’s not working. I’ve ommitted the HTML of the form as it’s alot of text. Let me know if thats needed and I’ll post it as well.
TIA
Here’s the script portion:

[CODE]
<script language=”JavaScript” type=”text/JavaScript”>
<!–
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf(“?”))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors=”,args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!=””) {
if (test.indexOf(‘isEmail’)!=-1) { p=val.indexOf(‘@’);
if (p<1 || p==(val.length-1)) errors+=’- ‘+nm+’ must contain an e-mail address.n’;
} else if (test!=’R’) { num = parseFloat(val);
if (isNaN(val)) errors+=’- ‘+nm+’ must contain a number.n’;
if (test.indexOf(‘inRange’) != -1) { p=test.indexOf(‘:’);
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+=’- ‘+nm+’ must contain a number between ‘+min+’ and ‘+max+’.n’;
} } } else if (test.charAt(0) == ‘R’) errors += ‘- ‘+nm+’ is required.n’; }
} if (errors) alert(‘The following error(s) occurred:n’+errors);
document.MM_returnValue = (errors == ”);
}
//–>
</script>[/CODE]

Form header:

[CODE]<form action=”res_process.php” method=”post” name=”reservation_form” target=”_self” id=”reservation_form” onSubmit=”MM_validateForm(‘first_name’,”,’R’,’surname’,”,’R’,’phone’,”,’R’,’enter_email’,”,’RisEmail’,’con firm_email’,”,’RisEmail’,’airport’,”,’R’,’sel_area’,”,’R’,’direction’,”,’R’,’town’,”,’R’,’area_ code’,”,’R’,’enter_date’,”,’R’,’hour’,”,’R’,’minute’,”,’R’,’flight_no’,”,’R’,’sel_PAX’,”,’R’,’ address’,”,’R’);return document.MM_returnValue”>[/CODE]

And after the HTML:

[CODE]
<input language=javascript id=btnSubmit style=”FONT-WEIGHT: bold; FONT-SIZE: 8pt; COLOR: navy; FONT-FAMILY: Tahoma” onClick=”if (typeof(Page_ClientValidate) == ‘function’) Page_ClientValidate(); ” tabindex=7 type=submit value=continue name=btnSubmit>

<script language=javascript>
<!–
var Page_Validators = new Array(document.all[“valDirectionRequired”]);
// –>
</script>
<script language=javascript>
<!–
var Page_ValidationActive = false;
if (typeof(clientInformation) != “undefined” && clientInformation.appName.indexOf(“Explorer”) != -1) {
if ((typeof(Page_ValidationVer) != “undefined”) && (Page_ValidationVer == “125”))
ValidatorOnLoad();
}

function ValidatorOnSubmit() {
if (Page_ValidationActive) {
ValidatorCommonOnSubmit();
}
}
// –>
</script>[/CODE]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Phil_KarrasJun 29.2004 — First I'd change that mess of a <form> tag to:
<i>
</i>&lt;form action="res_process.php" method="post" name="reservation_form" target="_self" id="reservation_form" onSubmit=" return MM_validateForm();"&gt;

The MM_validateForm function can pick up all the values it needs using:

document.forms[#].elements[#].value

or

document.reservation_form.RisEmail.value

I'll see if I have a simple example of validating a drop down list for you.

On my web site I have an example: help87.htm

which shows how to get the value of a drop-down list. In your case the example would be:
<i>
</i>document.reservation_form.DropListName.value


Here's a simple demo:
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;

&lt;title&gt;help292.htm - Drop Down List Value&lt;/title&gt;

&lt;script language="JavaScript" type="text/javascript"&gt; &lt;!--

// ###############################################
// ##### Test functions go here #####
// ###############################################

// -----------------------------------------------------
// Simply shows how to get the data value of a drop
// dowm SELECT statment.
//
// inputs: none, all come from the document.form
// outputs: none
// actions: displays the retrieved value
// returns: false, so the from doesn't try to do anything
// -----------------------------------------------------
function showValue() {
var Val = document.menu.ddOne.value;
alert("The value from ddOne is: ["+Val+"]");
return false;
}

// ###############################################
// ##### End of: test functions #####
// ###############################################

// --&gt; &lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;!--###############################################
// ##### Test body HTML code goes here #####
// ###############################################--&gt;

&lt;FORM NAME="menu" action="" onSubmit="return showValue();"&gt;
&lt;select name="ddOne"&gt;
&lt;OPTION VALUE="index.htm"&gt;Home Page&lt;/OPTION&gt;
&lt;OPTION VALUE="Phil Karras"&gt; My Name &lt;/OPTION&gt;
&lt;OPTION VALUE="help0022.htm"&gt;Dynamic Pulls Downs&lt;/OPTION&gt;
&lt;OPTION VALUE="help13.htm" &gt;Move a Div Page&lt;/OPTION&gt;
&lt;/select&gt;
&lt;INPUT type="submit" name="Submit" value="submit"&gt;
&lt;/FORM&gt;


&lt;!--###############################################
// ##### End of: body HTML code #####
// ###############################################--&gt;

&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@Phil_KarrasJun 29.2004 — Take another look at my previous post I have a simple example

posted in there now.
Copy linkTweet thisAlerts:
@sovtekauthorJun 29.2004 — [i]Originally posted by Phil Karras [/i]

[B]Take another look at my previous post I have a simple example

posted in there now. [/B]
[/QUOTE]


Cheers and thanks a million. Will see if I can get my head around it back at home.
Copy linkTweet thisAlerts:
@sovtekauthorJul 01.2004 — Thanks for the example.

The script I posted actually works now as I noticed the drop down list names didn't have quotes. I quoted them and then added their names to the form header.
×

Success!

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