homepage Welcome to WebmasterWorld Guest from 54.161.190.9
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Javascript error. Can anyone see where I'm going wrong?
fintan




msg:1472252
 9:26 am on Jun 13, 2003 (gmt 0)

<script language="JavaScript1.2" type="text/JavaScript">
<!--

function checkForm(){
//variable
var checkbox = document.forms[0].call_cleared.checked;
var category = document.forms[0].elements[0].options[document.forms[0].elements['cat'].selectedIndex].value
//variable

//conditional statment

if(category=="16" && checkbox == true){
alert("You must assign a category")
return false;
}
else{email() //Call function within function
return true;
}

}

function email(){

//variables
var checkbox = document.forms[0].call_cleared.checked;
var selected = document.forms[0].itstaff.selectedIndex;
var val = document.forms[0].itstaff.options[selected].value;
//variables

//conditional statments

//Checking to see if call is assigned
if(val == "16"){
return false;
}
//If call is closed send closure email
else{
if(checkbox == true){
window.open('/helpdesk/email/sendclosed.asp?callID=<%=(rscalls.Fields.Item("callID").Value)%>','','width=180,height=50','top=5000,left=5000')
}

//If call is open send email
else if(checkbox == false){
window.open('/helpdesk/email/sendnotice.asp?callID=<%=(rscalls.Fields.Item("callID").Value)%>','','width=180,height=50','top=5000,left=5000')
}
}

//conditional statments end

//-->
</script>

<form action="<%=MM_editAction%>" method="POST" name="form1" onSubmit="return checkForm()">

 

BlobFisk




msg:1472253
 9:52 am on Jun 13, 2003 (gmt 0)

Hey Fintan,

What exactly are you seeing wrong on your page?

[quote]
'top=5000,left=5000'
[/top]

These are very, very high - the popup will open well offscreen.

In your var category line, put a ";" at the end of the line, and also after emaail() here:

else{email() //Call function within function

A description of what seems to be going would be a big help.

fintan




msg:1472254
 10:21 am on Jun 13, 2003 (gmt 0)

Sorry

Ok We have two dropdown lists & one checkbox. Each fuction when on its own works fine. Never mind the asp in for the moment.
Basically in dropdown list "A" undetermined is an option and it has a value of 16. So if list "A" is undetermined and the checkbox is ticked don't process the form.

Now the second dropdown list "B" unassigned has a value of 16 as well. If "B" is unassigned don't send an email. But if it is assigned send email. It also checks to see if the checkbox is ticked which then decides the type of email to send.

Now what I want to do is bring them together.

ShawnR




msg:1472255
 11:42 am on Jun 13, 2003 (gmt 0)

I can see a whole bunch of things that I don't like style-wise (probably just my preference ... ;) But it would be better to understand the symptoms, rather than getting you to chase your tail tweaking things but ignoring the main problem.

fintan




msg:1472256
 11:58 am on Jun 13, 2003 (gmt 0)

Can you see where I went wrong. I need the alert to work first then the email decision.

korkus2000




msg:1472257
 12:08 pm on Jun 13, 2003 (gmt 0)

fintan I think we can help if you could give us a little more info:

1. What happens when you run this?
2. What do you not like about that?
3. What do you want it to do?

ShawnR




msg:1472258
 12:15 pm on Jun 13, 2003 (gmt 0)

Like I said, I can see a whole lot of problems... Not sure which will be the thing causing a real problem vs just poor style. For example, BlobFisk pointed out you left out some semicolons. Well, that is true, but most browsers are forgiving, so that is a problem, but probably not the problem.

So it really would help if you can explain the symptoms you are seeing. What happens in your browser?

But if I had to take a guess, I think the problem is here:


//If call is closed send closure email
else
{
if(checkbox == true){

should be

//If call is closed send closure email
else
if(checkbox == true){

(Or another way to fix it would be to add another } just before
//conditional statments end

//-->
</script>

Shawn

grahamstewart




msg:1472259
 12:21 pm on Jun 13, 2003 (gmt 0)

I think Shawn has solved your problem, but as an aside...
I hope you are checking the form dat on the server side as well and not just relying on this script to validate your form.

Because a) around 10% of users have javascript turned off and b) someone is bound to try sending you dodgy data anyway to see what happens.

fintan




msg:1472260
 12:54 pm on Jun 13, 2003 (gmt 0)

Its on an intranet site so dodgy data isn't something I have to worry about. Thanks for that I been staring at it for so long now I was starting to lose touch with reality. Oh I could make it neater but I need it done yesterday. Thanks again

fintan.

ShawnR




msg:1472261
 10:41 am on Jun 14, 2003 (gmt 0)

"...on an intranet site so dodgy data isn't something I have to worry about..."

I put the above sentence through a validator, and the result I got back is:

line 1, char 25: Semantic error: 'so' used to imply inference which is neither analytically nor synthetically rational. Hence by Hume's fork the statement is classified as 'non-sense'.

Good that you don't have to worry about it; makes things that much easier. ;) But just make sure that is a valid assumption.

Shawn

(PS. Don't get offended by the output of the validator. "non-sense" doesn't neccesarily mean 'BS'; it could just mean "information that can't be verified using your 5 senses" (hence non-sense data).)

g1smd




msg:1472262
 9:36 pm on Jun 14, 2003 (gmt 0)

Having it on an Intranet probably makes it more vunerable...

vunerable to childish people simple playing about, and vunerable to that disgruntled employee out to cause lots of damage on their last day.

Check it. Secure it.

fintan




msg:1472263
 8:58 am on Jun 16, 2003 (gmt 0)

Its for my IT department and its in there interest not to put in dodgy data.

ShawnR




msg:1472264
 12:34 pm on Jun 16, 2003 (gmt 0)

Don't mean to labour the point; all I want to do is point out the issue...

It may not be deliberate. IT people are precisely the sort of rebelious lot who decide to turn off javascript in their browser because they are sick of pop-ups or because they are better educated about spy-ware/scum-ware. If you are going to rely solely on javascript for form validation, then I suggest you use javascript to submit the form, and have the form's html action be null or point to a static html page which says 'sorry, you need to turn on javascript'. That way you force people who want to submit the form to turn on javascript.

Shawn

fintan




msg:1472265
 1:45 pm on Jun 16, 2003 (gmt 0)

Oh I get your point. I know if I was doing something on the internet I'd have to do it another way. Its just that in the environment that I'm in I'm lucky that I don't have to worry about such things. Its a small IT department.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved