mviverette
08-29-2003, 07:23 PM
The URL of the page I need help with is:
http://www.teampittsburgh.com/admin_announce.shtml
Here is my problem. When I hit the Add to database button, the form submits, unless the message box is blank. When I hit the reset button, i want the link to run function myReset(), but instead it submits the form because an input type=image field automatically submits the form. How do I work around this? Take a look at my code...
Javascript:
<script language = "Javascript">
function mySubmit() {
if (document.addannouncement.message.value == '') {
alert('You must enter a message for this announcement.');
return false;
}
else {
return true;
}
}
function myReset(which){
var pass=true
var first=-1
if (document.images){
for (i=0;i<which.length;i++){
var tempobj=which.elements[i]
if (tempobj.type=="text"){
eval(tempobj.value="")
if (first==-1) {first=i}
}
else if (tempobj.type=="checkbox") {
eval(tempobj.checked=0)
if (first==-1) {first=i}
}
else if (tempobj.col!="") {
eval(tempobj.value="")
if (first==-1) {first=i}
}
}
}
which.elements[first].focus()
return false
}
</script>
Submit buttons HTML:
<a href="javascript:document.addannouncement.submit()" onClick="return mySubmit()"><input type="image" border="0" name="imgSubmit" src="/admin/admin_announcements_db_add.gif" width="137" height="24"></a>
<a href="javascript:document.addannouncement.reset()" onClick="myReset(this)"><input type="image" border="0" name="imgReset" src="/admin/admin_announcements_db_reset.gif" width="137" height="24"></a>
Please help! I am available via e-mail at m a t t @ t e a m p i t t s b u r g h . c o m. Then I will provide you with my IM handle so we can work on it, or you could just tell me how to fix it!
Thanks for anybody who can help!
http://www.teampittsburgh.com/admin_announce.shtml
Here is my problem. When I hit the Add to database button, the form submits, unless the message box is blank. When I hit the reset button, i want the link to run function myReset(), but instead it submits the form because an input type=image field automatically submits the form. How do I work around this? Take a look at my code...
Javascript:
<script language = "Javascript">
function mySubmit() {
if (document.addannouncement.message.value == '') {
alert('You must enter a message for this announcement.');
return false;
}
else {
return true;
}
}
function myReset(which){
var pass=true
var first=-1
if (document.images){
for (i=0;i<which.length;i++){
var tempobj=which.elements[i]
if (tempobj.type=="text"){
eval(tempobj.value="")
if (first==-1) {first=i}
}
else if (tempobj.type=="checkbox") {
eval(tempobj.checked=0)
if (first==-1) {first=i}
}
else if (tempobj.col!="") {
eval(tempobj.value="")
if (first==-1) {first=i}
}
}
}
which.elements[first].focus()
return false
}
</script>
Submit buttons HTML:
<a href="javascript:document.addannouncement.submit()" onClick="return mySubmit()"><input type="image" border="0" name="imgSubmit" src="/admin/admin_announcements_db_add.gif" width="137" height="24"></a>
<a href="javascript:document.addannouncement.reset()" onClick="myReset(this)"><input type="image" border="0" name="imgReset" src="/admin/admin_announcements_db_reset.gif" width="137" height="24"></a>
Please help! I am available via e-mail at m a t t @ t e a m p i t t s b u r g h . c o m. Then I will provide you with my IM handle so we can work on it, or you could just tell me how to fix it!
Thanks for anybody who can help!