JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 14th, 2004, 08:58 PM
ocean ocean is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 18 ocean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How can a input submit call a function b4 submitting

Hi I am having problem modifying some feature of my proboard forum....well I want to first of all know how can I make an input button thats type of submit and already has something assigned to onClick call a little function I made in the header...

this is the code im facing...
Code:
<script>
<!-- this is the function i put in the header to be called
function check_sublength() {
  var allinputs = document.getElementsByTagName('input')
  for (i=0; i<allinputs.length;i++) {
    if (allinputs(i).name == "subject") {
      var subjin = allinputs(i)
      if (subjin.value == "") alert ("Empty subject field")
    }
  }
}
//-->
</script>

<!--This is in the footer( the bottom of the proboard code
<input type="hidden" name="waction" value="post">
<input type="submit" name="post" value="Post" onClick="document.postmodify.waction.value='post';" accesskey="s" tabindex="4">
I dont know how to link the submit button with the function....plz help..

Last edited by stumpy : February 14th, 2004 at 10:25 PM. Reason: Please place code in [CODE] tags

Reply With Quote
  #2  
Old February 14th, 2004, 10:20 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
You can a few different things here.
One - if you want to assign a button to an event such as onClick - then use input type=button, not submit.
Two, if you only want the function to run just before submitting, use the event method called onSubmit in the form tag. E.g. <form onSubmit="return checkLength()">. Notice the return statement. If your function returns a false, then the form will not be submitted. Obviosuly, a return true will submit the form.

Check out this site - http://www.htmlgoodies.com/tutors/fm.html - It goes through the all the basics of forms and javascript.

BTW - if your code is javascript, then your script tag should be written as follows: <script type="text/javascript">
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #3  
Old February 15th, 2004, 06:45 AM
ocean ocean is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 18 ocean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanx...but what if the form already has a value assigned to onSubmit...

Code:
<form action="index.cgi?board=computer&action=post2" method="post" name="postmodify" onSubmit="submitonce(this);">


can I add two values....how?

Reply With Quote
  #4  
Old February 15th, 2004, 05:12 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Create a new function that contains your function calls for the onSubmit event handler.
Code:
function onsubmit_functions() {
  submitonce(document.frmName)
  checkLength()
}

function submitone() {
...
}

functions checklength() {
...
}

<form onSubmit="onsubmit_functions()">

Reply With Quote
  #5  
Old February 16th, 2004, 07:26 PM
ocean ocean is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 18 ocean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I have tried to make the form call two functions. Everythings fine but why is the form still submitting to the location.....? I am returning false when needed but no response...what am i doing wrong?


<script type="text/javascript">
<!--
function check_post(){
var subjin;
var rtn = true;
var allinput = document.getElementsByTagName('input')
for (i=0; i < allinput.length; i++){
if (allinput(i).name == 'subject'){
subjin = allinput(i);
if (subjin.value == ""){
alert ("No Subject Specified")
rtn = false;
break;
}
}
}
return (rtn);
}
//-->
</script>

<script type="text/javascript">
<!--fag
function submit_call(theform){
var rtn2 = check_post();
if (rtn2 == true){
if (document.all || document.getElementById) {
for (i=0;i<theform.length;i++) {
var tempobj=theform.elements[i];
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset") {
tempobj.disabled=true;
}
}
}
}
else {
rtn2 = false;
}

return (rtn2);
}

//-->
</script>

<form action="index.cgi?board=announcements&action=post2" method="post" name="postmodify" onSubmit="submit_call(this);">

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > How can a input submit call a function b4 submitting


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT