Author |
Topic  |
Roland
Advanced Member
    
Netherlands
9335 Posts |
Posted - 14 May 2002 : 16:04:02
|
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
|
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 |
 |
|
Roland
Advanced Member
    
Netherlands
9335 Posts |
Posted - 14 May 2002 : 16:35:20
|
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 |
 |
|
Steve D.
Average Member
  
USA
640 Posts |
|
ruirib
Snitz Forums Admin
    
Portugal
26364 Posts |
Posted - 14 May 2002 : 16:45:26
|
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 |
 |
|
Steve D.
Average Member
  
USA
640 Posts |
Posted - 14 May 2002 : 16:50:22
|
Here's another good tutorial on form validation
---------------------------------------- Badges? We don't need no stinking badges |
 |
|
Roland
Advanced Member
    
Netherlands
9335 Posts |
Posted - 14 May 2002 : 17:00:03
|
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 |
 |
|
ruirib
Snitz Forums Admin
    
Portugal
26364 Posts |
Posted - 14 May 2002 : 17:23:56
|
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 |
 |
|
RichardKinser
Snitz Forums Admin
    
USA
16655 Posts |
|
Kat
Advanced Member
    
United Kingdom
3065 Posts |
Posted - 15 May 2002 : 04:21:57
|
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
|
 |
|
SubKamran
Junior Member
 
101 Posts |
Posted - 15 May 2002 : 11:14:52
|
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 |
 |
|
SubKamran
Junior Member
 
101 Posts |
Posted - 15 May 2002 : 11:18:07
|
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 |
 |
|
Roland
Advanced Member
    
Netherlands
9335 Posts |
Posted - 15 May 2002 : 11:24:32
|
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 |
 |
|
SubKamran
Junior Member
 
101 Posts |
Posted - 15 May 2002 : 11:27:53
|
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 |
 |
|
nomad_2k
Junior Member
 
United Kingdom
173 Posts |
Posted - 15 May 2002 : 12:00:16
|
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/ |
 |
|
Roland
Advanced Member
    
Netherlands
9335 Posts |
Posted - 15 May 2002 : 14:30:53
|
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 |
 |
|
Topic  |
|