Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Html n Java Script Probs

Options
  • 07-07-2001 7:17pm
    #1
    Registered Users Posts: 2,651 ✭✭✭


    Hey ho,

    I can't do something and i was wondering if anyone there could. I have it is easy to solve if ya know ur stuff, but i guess i don't.

    I want to join these two or at least try to get them both working.

    <form method="POST" onSubmit="submitonce(this)">

    <form method="POST" onSubmit="return checkrequired(this)">

    They are both part of a form, and operate after ya press submit.
    They are part of two seprate java scripts, one for each, which are located in the head section of the webpage.

    any ideas?

    Cheers,
    Gideon.


Comments

  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    Gideon,

    K I will give this a go, but I am still not too sure what you want, but this is what I can make of it anyway. Your problem is that you want to call two methods/functions upon form submission, but can't, right?. If that is the problem then here is the sollution...

    Up in the head section of the HTML document where you defined submitonce(frmObject), go to the very end of the definition before the closing brace "}". At that point insert return checkrequired(frmObject)

    So now your definitions look like this
    function submitonce(frmObject){
        .
        .
        return return checkrequired(frmObject)
    }
    

    What I am doing is simply calling checkrequired() from submitonce(). This will enable both methods to be called upon form submission. So now your HTML code will simply change to <form method="POST" onSubmit="submitonce(this)">, with no need for <form method="POST" onSubmit="return checkrequired(this)">

    Anyway hope this helps :-)

    :-phobos-)


  • Registered Users Posts: 2,651 ✭✭✭Spunog UIE



    Hey i tried doing what you said but i think it was a little bit over my head. And it didnt' really work out. frown.gif
    Here are the 2scripts in their interity. The head bit followed by the form bit. I got them both off different websites.
    The submit once one allows forms only to be submitted once and the checker just makes sure all the fields are filled in. I can get the both to work by themselves but can't together.
    I've messed up my form page so much now trying to get the two of them to work that other things have started to go astray. arg, hate it when that happens. Anyhew, see what ya can do please. Mmmmm ya i want them both to execute at the same time when the submit button is pushed.


    Submit Once
    &lt;script&gt;
    
    function submitonce(theform){
    //if IE 4+ or NS 6+
    if (document.all&#0124;&#0124;document.getElementById){
    //screen thru every element in the form, and hunt down "submit" and "reset"
    for (i=0;i&lt;theform.length;i++){
    var tempobj=theform.elements[i]
    if(tempobj.type.toLowerCase()=="submit"&#0124;&#0124;tempobj.type.toLowerCase()=="reset")
    //disable em
    tempobj.disabled=true
    }
    }
    }
    &lt;/script&gt;
    
    ...
    
    &lt;form method="POST" onSubmit="submitonce(this)"&gt;
    


    Checker
    &lt;script&gt;
    
    function checkrequired(which){
    var pass=true
    if (document.images){
    for (i=0;i&lt;which.length;i++){
    var tempobj=which.elements[i]
    if (tempobj.name.substring(0,8)=="required"){
    if (((tempobj.type=="text"&#0124;&#0124;tempobj.type=="textarea")&&tempobj.value=='')&#0124;&#0124;(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
    pass=false
    break
    }
    }
    }
    }
    if (!pass){
    alert("One or more of the required elements are not completed. Please complete them, then submit again!")
    return false
    }
    else
    return true
    }
    &lt;/script&gt;
    
    ...
    
    &lt;form onSubmit="return checkrequired(this)"&gt;
    

    frown.gif



  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    OK don't worry m8, I've got it sorted.

    Let me just explain to you how this is going to work. As you pointed out the submitonce function disables the submit & reset buttons. So once the form contents have successfully been sent, that would be the ideal time to disable those buttons. Think about it. When the user clicks on the submit button the first thing you should do is check and see if all the required fields have been "filled in". If that has been done, then disable the two buttons, but not before then. So by modifying your code I simply produced the following
    function checkrequired(which){
    var pass=true
    if (document.images){
        for (i=0;i&lt;which.length;i++){
            var tempobj=which.elements[i]
            if (tempobj.name.substring(0,8) =="required"){
                 if(((tempobj.type=="text"&#0124;&#0124;tempobj.type=="textarea")&&tempobj.value=='')&#0124;&#0124;(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
    pass=falsebreak}}}}
    
    if (!pass){
        alert("One or more of the required elements are not completed. Please complete them, then submit again!")}
    else
    {
    submitonce(which)
    }
    }
    &lt;/script&gt;
    
    and the HTML call will be as follows:
    &lt;form method="POST" onSubmit="checkrequired(this)"&gt;
    

    So just to recap. Your HEAD section of the HTML document will only change by adding that little bit to the end of the checkrequired() function. And in the HTML form you will only need to call the checkrequired() function.

    This will work. I hope it makes sense now!

    ;-phobos-)

    [This message has been edited by phobos (edited 07-07-2001).]


  • Registered Users Posts: 12,309 ✭✭✭✭Bard


    I presume that if someone has JavaScript disabled in their web browser, your form will be broken then?

    Just a thought...


  • Registered Users Posts: 2,651 ✭✭✭Spunog UIE



    The bit inside the head tag
    &lt;head&gt;
    &lt;title&gt;Gideon's Contact Form&lt;/title&gt;
    
    &lt;script&gt;
    function checkrequired(which){
    var pass=true
    if (document.images){
        for (i=0;i&lt;which.length;i++){
            var tempobj=which.elements[i]
            if (tempobj.name.substring(0,8) =="required"){
                 if(((tempobj.type=="text"&#0124;&#0124;tempobj.type=="textarea")&&tempobj.value=='')&#0124;&#0124;(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
    pass=falsebreak}}}}
    if (!pass){
        alert("One or more of the required elements are not completed. Please complete them, then submit again!")}
    else
    {
    submitonce(which)
    }
    }
    &lt;/script&gt;
    
    
    &lt;script&gt;
    
    function submitonce(theform){
    //if IE 4+ or NS 6+
    if (document.all&#0124;&#0124;document.getElementById){
    //screen thru every element in the form, and hunt down "submit" and "reset"
    for (i=0;i&lt;theform.length;i++){
    var tempobj=theform.elements[i]
    if(tempobj.type.toLowerCase()=="submit"&#0124;&#0124;tempobj.type.toLowerCase()=="reset")
    //disable em
    tempobj.disabled=true
    }
    }
    }
    &lt;/script&gt;
    

    and the form its-self
    &lt;form method=post action="http://us.geocities.yahoo.com/forms" onSubmit="checkrequired(this)"&gt;&lt;font face="arial, helvetica"&gt; 
                                      &lt;div align="left"&gt;&lt;b&gt;Name:&lt;/b&gt;&lt;br&gt;
                                        &lt;input type="text" name="requiredname" size="27"&gt;
                                      &lt;/div&gt;
                                      &lt;p align="left"&gt; &lt;b&gt;E-mail:&lt;/b&gt;&lt;br&gt;
                                        &lt;input type="text" name="requiredemail" size="27"&gt;
                                      &lt;/font&gt;&lt;p align="left"&gt;&lt;font face="arial, helvetica"&gt; &lt;b&gt;Please add any comments 
                                        or&lt;br&gt;
                                        suggestions you have for Gideon's Place: &lt;/b&gt;&lt;/font&gt;&lt;br&gt;
                                        &lt;textarea cols="40" rows="10" name="requiredcomments"&gt;&lt;/textarea&gt;
                                      &lt;p align="left"&gt;&lt;br&gt;
                                        &lt;input type="submit" value="Send"&gt;
                                        &lt;input type="reset" value="Clear the form"&gt;
                                        &lt;input type="hidden" name="login" value="gideon22333"&gt;
                                        &lt;!-- Option 1 --&gt;
                                        &lt;input type="hidden" name="subject" value="Mail from Site"&gt;
                                        &lt;!-- Option 2 --&gt;
                                        &lt;input type="hidden" name="next_url" value="http://www.geocities.com/gideon22333/thankyou.htm"&gt;
                                        &lt;!-- Option 3 --&gt;
                                        &lt;input type="hidden" name="required_fields" value="name,email"&gt;
                                    &lt;/form&gt;
    

    So where am i going wrong? i'm just guessin at this stage and messin around with it but i think i'm totally lost. Guess it ain't my strong pt hmmmmm.
    sorry for all the hassel n cheers for da help.


  • Advertisement
  • Registered Users Posts: 2,651 ✭✭✭Spunog UIE


    <font face="Verdana, Arial" size="2">Originally posted by Bard:
    I presume that if someone has JavaScript disabled in their web browser, your form will be broken then?
    </font>

    Not sure...but gettin a lot of that lately. mmmmm most of the scripts are just to make sure you fill in the thing correctly and that to prevent spamming of it like clicking the thing loads of times etc' but not sure if the form its self works totally on scripts. As far as i can see ppl with javascripts turned off just not get the safety of it, then again i could be wrong, but the form its self is html. :S i just want the bloody thing to work.



    [This message has been edited by Gideon2000 (edited 07-07-2001).]


Advertisement