Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form output help

    Can anyone tell me how to get the alert box to display in text instead. So when the user clicks on the submit button instead of an alert box, the result would display below the button in text instead of an alert? Any suggestions?
    <script type = "text/javascript">

    function validate (form){
    var hrs=(form.hrs[0].checked)? form.hrs[0].value : form.hrs[1].value;

    var flname = form.fullname.value;
    flname = flname.replace(/[^a-zA-Z\s-/']/g,"");
    if (flname.length < 5) {
    alert ("Please re-enter your FULL NAME.");
    return false;
    }

    var age = document.form1.yrs.value;
    if (age == 0) { // nothing selected
    alert ("Please select your age")
    return false;
    }

    var calc=((hrs*form.yrs.value)/12).toFixed(2);
    alert ("You spend " + calc +" years playing silly computer games")

    alert("Thanks " + flname + " for completing the form correctly.");
    return true; // return true is the default so this line is not required
    }
    </script>

    </HEAD>
    <BODY>
    <FORM METHOD="post" name="form1" onSubmit="return validate(this)";
    <!-- START HTML -->
    <TABLE>
    <TR>
    <TH ALIGN="Left" COLSPAN="2"><H1> <U>HOURS SPENT PLAYING VIDEO GAMES</U></H1></TH>
    </TR>
    <TR>
    <TD><B> FULL NAME: </B></TD>
    <TD width="608"><INPUT NAME="fullname" TYPE="text"> (letters only) </TD>
    </TR>
    <TR>
    <TD><B> HOURS A DAY: </B> </TD>
    <TD><B><INPUT TYPE="radio" NAME="hrs" VALUE="2">2</B>
    <B><INPUT TYPE="radio" NAME="hrs" VALUE="3" >3</B></TD>
    </TR>
    <TR>
    <TD><B> how old are you?: </B></TD>
    <TD><SELECT NAME="yrs">
    <OPTION VALUE=""> How old are you </option>
    <option value="01">1</option>
    <option value="02">2</option>
    </SELECT>
    </TD>
    </TR>
    <!-- BUTTON -->
    <tr>
    <td colspan="2"><INPUT TYPE="submit" VALUE="SEND DATA"><INPUT TYPE="reset" VALUE="CLEAR FORM"></td>
    </tr>
    </TABLE>
    </FORM>
    </BODY>

  • #2
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    kinda like this I think

    use innerHTML

    Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    
    </head>
    
    <body >
    
    
    <script type = "text/javascript">
    function doit(){
    document.getElementById("someDiv").innerHTML="give it the html here"
    }
    
    </script>
    <div ID="someDiv"></div>
    <a href="#" onclick="doit()">do it</a>
    </body>
    </html>

  • #3
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    okay i'll try it out, Thank You


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •