Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript newbie - function question

Status
Not open for further replies.

ecojohnson

Programmer
Jul 2, 2001
54
US
I'm guessing it's probably obvious, but does anyone see what's wrong with my javascript function? I don't see it.

function Delete()
{
if (confirm ("Are you sure you want to delete the selected record?"))
{
if (document.forms[0].List.value=("New"));
{
alert("You cannot delete this record")
return false
}
else
{
document.forms[0].hiddenfield.value=("Delete");
document.forms[0].submit();
}
{
return false
}
}
}
 
What do you get when you run the code and what are you trying to get?
 
i change the code like those:

function Delete()
{
if (confirm ("Are you sure you want to delete the selected record?"))
{
if (document.forms[0].List.value=("New"));
{
alert("You cannot delete this record")
return false
}else{
document.forms[0].hiddenfield.value=("Delete");
document.forms[0].submit();
}
}else{
return false
}

}
 
It would be good if you told us what the errors were, but I can tell you what's wrong that I see.
//////////////////////////////////////////////


function Delete()
{
//I assume you have made a function called confirm that returns true or false?
if (confirm ("Are you sure you want to delete the selected record?"))
{
//This should be == double equals which means 'equal to' the single means 'equals' (Ichanged it)
if (document.forms[0].List.value=="New");

{
alert("You cannot delete this record")
return false
}
else
{
document.forms[0].hiddenfield.value=="Delete";
document.forms[0].submit();


return true;
}
}
}
 
The error I received said it was a syntax error (sorry about omitting that part).

All I am trying to do is to first check if the user selected the item "New". If they did, I wanted to return the alert "Are you sure you want to delete the selected record". If they pick anything else, I wanted to rest of the fuction to complete.

Thanks for the latest tip. I will give it a shot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top