Hi, I’m relatively new to javascript – so I’m hoping this is a real newbie error. But I’ve tried lots and cant fathom it out.
ok, so I have saved off all my javascript to two .js files. The first is very much a set of form validation functions. The second is just a function with a case statement in.
We have a html page listing a bunch of options in a drop down selection box.
On submit, a function called Validate is called. This function is in js 1. It checks to make sure the user has entered a name, address etc… and then it comes to the final check, that of the option box. Now for any option selected, three variables have to be assigned, like retURL as well as few database specific ones.
So once all the easy validation stuff is done, I call a function that sits in the other js file. Now if I just use the one js file, it all works, if I try to use two – the second function doesn’t seem to pick up the form variable.
Here is a simplified version of the two sets of code:
In js one:
[CODE]
function validate()
{
with (document.webform)
{
var alertMessage = “Please enter:n”;
// USER VALIDATION
if (Campaign_ID.value == “”) alertMessage += “nChoose Item”;
if (name.value == “”) alertMessage += “nName”;
if (address.value == “”) alertMessage += “nAddress”;
if (email.value == “”) alertMessage += “nEmail”;
// DISPLAY ALERT
if (alertMessage != “Please enter:n”)
{
alert(alertMessage);
return (false);
}
campaign();
return (true);
}
}
and here is the second js file in it’s entirety:
[CODE]
function campaign()
{
switch(Campaign_ID.value)
{
case ‘1234567890’:
elements(“0000000000XXX”).value=”Item X chosen”;
elements(“0000000000YYY”).value=”Item X chosen”;
elements(“retURL”).value=”http://www.website.com”;
break;
}
}
So on the actual web form, there is a drop down selection window, where you can choose from a number of items. I have just listed one above, but there will be lots. I’m just testing it with one currently. The value of the selection would be set to that 10 digit code seen in the case expression.
Where am I going wrong? I know the second js file gets called because I stuck an alert in there before the case expression. See, in the first js file, if I do something like:
alert(elements(“Campaign_ID”).value);
I get the correct value displayed on screen, but if I put that same alert before the case expression in the second file, it errors and nothing happens.
Now I know I could just stick it all in one js file and be done with it, but there maybe other js files at some point with more and more campaigns for different areas. Plus I would just like to know why it doesn’t work, it’s bugging me now ?