Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 JavaScript form validation Q
 New Topic  Topic Locked
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

Roland
Advanced Member

Netherlands
9335 Posts

Posted - 14 May 2002 :  16:04:02  Show Profile
I didn't want to put this in the Community Discussions so here goes:

I have a contact form on my site which has a couple required fields. So far so good, 'cause it works. Now, I have a select box for the subjects, one of which is "Other". If that one is selected, the user should enter the correct subject in the next text field. The problem is that they don't have to because there's no validation to see if "Other" has been selected and if so, the next field is required.

Is that possible with JavaScript or would you recommend using ASP for the validation? I can take a look at the forum registration's validation to get the other fields, but how would I go about doing what I want?

To be honest, I don't even know if it's possible at all, but the reason I went with a JS file is that I was using it on an old site and it's really simple and I've been re-using it for a long time. Also the alert boxes are nicer than a warning page.




http://www.frutzle.com

Snitz Exchange | Do's and Dont's

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 14 May 2002 :  16:28:19  Show Profile  Send ruirib a Yahoo! Message
I'm no Javascript expert at all but I would say that is definitely possible. I may help if required (although that will mean a need for a refresh on some things I've done in Javascript for my site), but possibly someone else with more experience with Javascript can do it faster. But I'll help you if you need it.

-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page

Roland
Advanced Member

Netherlands
9335 Posts

Posted - 14 May 2002 :  16:35:20  Show Profile
quote:

I'm no Javascript expert at all but I would say that is definitely possible.


The only JavaScript I know is Open Dreamweaver, click on Behaviors and insert them Can't write a single line myself...

quote:

I may help if required (although that will mean a need for a refresh on some things I've done in Javascript for my site), but possibly someone else with more experience with Javascript can do it faster. But I'll help you if you need it.


Thanks. I appreciate the offer and will take you up on it if I can't find the answer anywhere online (why are all JavaScript related sites about "goodies" instead of useful codes like what I need? lol) and nobody else can help




http://www.frutzle.com

Snitz Exchange | Do's and Dont's
Go to Top of Page

Steve D.
Average Member

USA
640 Posts

Posted - 14 May 2002 :  16:37:59  Show Profile  Visit Steve D.'s Homepage  Send Steve D. a Yahoo! Message
here is a link I found

http://www.4guysfromrolla.com/webtech/020499-1.shtml

----------------------------------------
Badges? We don't need no stinking badges
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 14 May 2002 :  16:45:26  Show Profile  Send ruirib a Yahoo! Message
quote:

The only JavaScript I know is Open Dreamweaver, click on Behaviors and insert them Can't write a single line myself...


I can code it with a Javascript book by my side (that's how I did the form validation for my site 6 months ago). The problem with this approach is that I forget about how to do things as soon as I stop using the language...

quote:

Thanks. I appreciate the offer and will take you up on it if I can't find the answer anywhere online (why are all JavaScript related sites about "goodies" instead of useful codes like what I need? lol) and nobody else can help


I'll be glad to help. So don't hesitate in case the need persists.


-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page

Steve D.
Average Member

USA
640 Posts

Posted - 14 May 2002 :  16:50:22  Show Profile  Visit Steve D.'s Homepage  Send Steve D. a Yahoo! Message
Here's another good tutorial on form validation

----------------------------------------
Badges? We don't need no stinking badges
Go to Top of Page

Roland
Advanced Member

Netherlands
9335 Posts

Posted - 14 May 2002 :  17:00:03  Show Profile
Steve D, it's not the validation itself that's the problem, but the validation of a select box item versus a text field. If a specific select box option is selected, the text box should become required, otherwise it shouldn't.




http://www.frutzle.com

Snitz Exchange | Do's and Dont's
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 14 May 2002 :  17:23:56  Show Profile  Send ruirib a Yahoo! Message
FrutZle, I'll have a look at this, since it looks simple enough. Can you provide a link to the page where you want to insert this validation?

-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page

RichardKinser
Snitz Forums Admin

USA
16655 Posts

Posted - 14 May 2002 :  17:26:30  Show Profile
there are quite a few examples here:

http://javascript.internet.com/forms/
Go to Top of Page

Kat
Advanced Member

United Kingdom
3065 Posts

Posted - 15 May 2002 :  04:21:57  Show Profile  Visit Kat's Homepage
Frutzle, it depends on whether you have hardcoded the select box values and therefore know the index of the 'Other' option, as to how easy this will be.

KatsKorner

Installation Help | Snitz Mods | Forum Hosting
Go to Top of Page

SubKamran
Junior Member

101 Posts

Posted - 15 May 2002 :  11:14:52  Show Profile  Visit SubKamran's Homepage  Send SubKamran an AOL message  Send SubKamran a Yahoo! Message
Here's what I'd write for it...

<%

If Request.Form("SelectBox") = "Other" Then
If Trim(Request.Form("Other") = "" Then
%>
<center>Sorry, please enter a value for 'Other'</center>
<%
End If
End If
%>

Kamran A
14/m/mn
Minneapolis, MN
Web Dev/Flash Dev
Go to Top of Page

SubKamran
Junior Member

101 Posts

Posted - 15 May 2002 :  11:18:07  Show Profile  Visit SubKamran's Homepage  Send SubKamran an AOL message  Send SubKamran a Yahoo! Message
quote:

Here's what I'd write for it...

<%

If Request.Form("SelectBox") = "Other" Then
If Trim(Request.Form("Other") = "" Then
%>
<center>Sorry, please enter a value for 'Other'</center>
<%
End If
End If
%>



Or instead of <center>****</center> I'd actually say:
Response.Redirect "feedback.asp?Error=Other"
Although that takes a whole nother step into it...but, with the above code, it will still send the email unless you do a little something...I don't know if ur hard coding the 'Send Mail' handler, so javascript would be good if u aren't...

Kamran A
14/m/mn
Minneapolis, MN
Web Dev/Flash Dev
Go to Top of Page

Roland
Advanced Member

Netherlands
9335 Posts

Posted - 15 May 2002 :  11:24:32  Show Profile
quote:

Frutzle, it depends on whether you have hardcoded the select box values and therefore know the index of the 'Other' option, as to how easy this will be.



Yep, it's hard coded. I only have one form so no need to make it dynamic.

Subkamran:
I can't use that kind of code. I personally don't like an error page because if you make a mistake, you have to wait for that page to load and then go back. Alert boxes are a lot easier: Oops, you made a mistake [OK] => correct field is selected.

Ruirib:
I'll mail you the URL. The site is still in testing phase and I don't want to have the URL public just yet. Thanks.

Richard, Kat, Subkamran, thank you all too. I'll defenately take a look at the sites you posted links to.




http://www.frutzle.com

Snitz Exchange | Do's and Dont's
Go to Top of Page

SubKamran
Junior Member

101 Posts

Posted - 15 May 2002 :  11:27:53  Show Profile  Visit SubKamran's Homepage  Send SubKamran an AOL message  Send SubKamran a Yahoo! Message
Did I mention you could create a Sub to have a msgbox? That would work too, I'm guessing...at least, in .NET u can...

Kamran A
14/m/mn
Minneapolis, MN
Web Dev/Flash Dev
Go to Top of Page

nomad_2k
Junior Member

United Kingdom
173 Posts

Posted - 15 May 2002 :  12:00:16  Show Profile
How about this:

<script language="JavaScript" type="text/javascript">
function validForm(p_objForm)
{
var strSelectValue = p_objForm.SelectBox.options[p_objForm.SelectBox.selectedIndex].value;

if (strSelectValue == "Other") {
var strTextValue = p_objForm.TextBox.value;

if (strTextValue.length = 0) {
alert("You must enter a value.");
return false;
}
}

return true;
}
</script>
<form action="somepage.asp" onsubmit="javascript: return validForm(this);">
<select name="SelectBox">
<option value="x">x</option>
<option value="y">y</option>
<option value="z">z</option>
<option value="Other">Other</option>
</select>
<br />
<input type="text" name="TextField" />
</form>



Good things come to those who wait.
http://www.freeasphost.co.uk/evolution/
Go to Top of Page

Roland
Advanced Member

Netherlands
9335 Posts

Posted - 15 May 2002 :  14:30:53  Show Profile
Okay, well it looks like the validation code created by Dreamweaver is too complex (looks like jibberish to me) to simply insert that code. I'll wait to see if Ruirib can figure something out, otherwise I'll have to find some validation script that I can actually understand.

Thanks for all your help guys & gals



http://www.frutzle.com

Snitz Exchange | Do's and Dont's
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.68 seconds. Powered By: Snitz Forums 2000 Version 3.4.07