PDA

View Full Version : is this allowed



cdc515
Oct 20th, 2009, 12:00 AM
I am new to javascript and on my webpage i have a javascript for my rollover images and on the webpage i also have a form that i want validated and whenever i add validation in only one of the javascripts work how do i get both of them to work at the same time on the same page?

oracleguy
Oct 20th, 2009, 12:07 AM
You can have multiple scripts on the same page without issue. Post the code or put up a link to the page so we can see what the issue is.

cdc515
Oct 20th, 2009, 12:33 AM
the website is www. .com/res_off.cfm

i have not validated all the required fields yet and i know that i was just testing to see why it wasnt working with any of them.

Thank You
for your help

Old Pedant
Oct 20th, 2009, 12:53 AM
You have an error in the monstrous regular expression you used in your email check...the one that starts with:

var regex = /^[-_.a-z0-9][email protected](([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|

So your code won't even start to run work until you fix that.

cdc515
Oct 20th, 2009, 01:26 AM
ok i got that working but when i tested it i got the error message i wanted but then it went to my confirmation page anyway why is that? It was supose to give an error message and not send the form if the field is empty and the set focus to that txt field.

Old Pedant
Oct 20th, 2009, 01:38 AM
You *MUST* return false *TO THE EVENT* in order to cancel the onsubmit.

That is, you must code:

<form action="response.php" method="post" name="contactForm"
onsubmit="return checkForm();" >

That assumes, of course, that your checkForm function is returning true/false.

Let me check that...

Yes. It is. Should work.

cdc515
Oct 20th, 2009, 02:18 AM
so it should work you are saying. so why isnt it ? it still proceeds through to the response.php and then to my confirmation page

Old Pedant
Oct 20th, 2009, 02:29 AM
See the code in red in my prior post???

The code should work *AFTER* YOU PUT THAT IN.

I just checked your page:
http://www.corporateexpressinc.com/res_off.cfm
and you *still* don't have the return in there.

Old Pedant
Oct 20th, 2009, 02:41 AM
The code *could* be somewhat simplified:


function checkForm()
{
with(window.document.contactForm)
{
if( (pickupaddress.value = trim(pickupaddress.value) ) == '')
{
alert('Please enter pickup address');
pickupaddress.focus();
return false;
}
if( (pickupcity.value = trim(pickupcity.value) ) == '')
{
alert('Please enter pickup city');
pickupcity.focus();
return false;
}
if( (pickupzip.value = trim(pickupzip.value) ) == '')
{
alert('Please enter pickup zip code');
pickupzip.focus();
return false;
}
return true;
}
}


Or we could go even simpler:


function checkForm(form)
{
var fields = ["address","city","zip"];
for ( var f = 0; f < fields.length; ++f )
{
var field = form.elements[fields[f]];
if( (field.value = trim(field.value) ) == '')
{
alert('Please enter pickup ' + field[f]);
field.focus();
return false;
}
}
return true;
}

and then make sure to pass this when invoking that from the <form> tag:


<form action="response.php" method="post" name="contactForm"
onsubmit="return checkForm(this);" >

cdc515
Oct 20th, 2009, 02:45 AM
Thank You everything is working great now.

I was wondering if you could help me with a different problem.

I coded the php script and that sends an email to me but my host switched recently to a windows server he told me for the php form to work, i needed to set the mail server information because it is a windows server where do i do that in the php script ? or is it something the host has to do? he also said If you don't set the mail server settings it won't know how to send the mail and nothing will happen.


ANy idea how to get this done? i googled it every which way and got nothing.

Old Pedant
Oct 20th, 2009, 02:52 AM
Ummm...no, everything is *NOT* working. If I choose a valid pickup date, I still get the message "please choose a pickup day".

And the reason for that is because your <select> *DOES NOT HAVE ANY VALUE*!

You coded:


<select name="pickupday" class="pole1" id="day">
<option value=''>Select Day</option>
<option>1</option>
<option>2</option>
etc.

When you do that, there is no value for form.pickupday.value.

You MUST actually enter a value= into the <option>:


<select name="pickupday" class="pole1" id="day">
<option value=''>Select Day</option>
<option value="1">1</option>
<option value="2">2</option>
etc.

You could also fix it in your JS code, but that's probably more work than just adding the value= stuff.

p.s.: Might work in some browsers, but not in all, for sure.

**********

Sorry, can't help you with the mail server information. I'm not a PHP person. I would say that your host should tell you that, actually. Especially if the host initiated the switch. Other than that, change hosts.

cdc515
Oct 20th, 2009, 03:47 AM
I have uploaded the updated file everything is working now thank you for all your help now i will be working on better validation for the fields that require numbers and the ones that require email thank you for your help