If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Oh please bloomin validate!!!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-26-05, 18:18
ASP-irations ASP-irations is offline
Registered User
 
Join Date: Jan 2005
Posts: 7
Oh please bloomin validate!!!

Im new to this ASP and Javascript thingy and so already got problems. I have a form with a text box on which i have used Javascript to validate so if nothing is entered an alert pops up.

before my code for the form was:

FORM onSubmit="return validate(this);"

and the validation worked fine. In order to use the form properly I made it get a file. Now my code is

FORM action="result.asp" method="get" onSubmit="return validate(this);"

and now the pop up doesnt appear if nothing is entered. Instead

result.asp?searchfield=

gets appended to the url. Please help its driving me mad!!!
Reply With Quote
  #2 (permalink)  
Old 01-26-05, 23:51
DrewM DrewM is offline
Registered User
 
Join Date: Jan 2005
Posts: 36
What's happening is the form is being submitted now to result.asp, in the earlier version you were calling JS. The ?searchfield= is being appended because you have method = GET.

Maybe do this

<form name="myform" method="post" action="result.asp">

Then on your submit button - call the validate Javascript

The validate JS has the alerts if the entries are not correct.

If they are correct then

document.myform.submit();

This will then submit your page to result.asp only if the form is filled out
Reply With Quote
  #3 (permalink)  
Old 01-28-05, 19:06
ASP-irations ASP-irations is offline
Registered User
 
Join Date: Jan 2005
Posts: 7
Ok now im confused.

my form now has method="post" and a name="myform". I have put the "return validate(this);" in the submit button tag instead of the form tag. My JS code now reads:

function validate(f){

if(f.search.value==""){
alert("Please enter details into search box");
f.search.focus();
return false;
}
return true;
document.myform.submit()

}

I know im doing something wrong cos its still not working. Before u ask:

Yes I am thick
No i havent got a clue
Yes i have never done this in my life before
Reply With Quote
  #4 (permalink)  
Old 01-28-05, 20:03
DrewM DrewM is offline
Registered User
 
Join Date: Jan 2005
Posts: 36
Do this,

on your submit button make sure you have
type="button"
onclick ="validate()"

then

function validate(){

if(document.myform.search.value==""){
alert("Please enter details into search box");
document.myform.search.focus();
}
else {
document.myform.submit()
}
}

Try that - it should work
Reply With Quote
  #5 (permalink)  
Old 01-28-05, 22:07
gyuan gyuan is offline
Registered User
 
Join Date: Dec 2003
Posts: 454
function validate() {
if (document.searchForm.searchText.value == "") {
alert("You did not enter the search keywords.");
return false;
}
else
return true;
}

<form action="result.asp" method="post" name="searchForm" onsubmit="if(validate()) document.searchForm.submit(); else false;">
<input type="Text" name="searchText" value="">
<input type="Submit" name="search" value="Search">
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On