Jagst3r15's Profile User Rating: -----

Reputation: 1 Apprentice
Active Members
Active Posts:
77 (0.04 per day)
21-December 10
Profile Views:
Last Active:
User is offline Apr 06 2014 06:00 AM

Previous Fields

OS Preference:
Favorite Browser:
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
Icon   Jagst3r15 has not set their status

Posts I've Made

  1. In Topic: Validate an HTML Form via JS

    Posted 18 Nov 2013

    Ok some parts are working, but I cannot get the validation working for the checkboxes or radio buttons. Also not sure about these parts: If the form is not populated correctly then display an error message. If the data in the form is valid then display the contents of each field in the text area of the form.

    But here it is so far:

    <!DOCTYPE html>
    		<title>Lab 11</title>
    		<script type="text/javascript">
    		// Form validation code will come here.
    		function validate() {
    		   if( document.myForm.room.value == "" ) {
    		     alert( "Please select a room option." );
    		     return false;
    		   if( document.myForm.activity.value == "" ) {
    		     alert( "Please select an activity." );
    		     return false;
    		   if( document.myForm.hotelname.value == "-1" ) {
    		     alert( "Please select a hotel name." );
    		     return false;
    		   if( document.myForm.name.value == "" ) {
    		     alert( "Please provide your name." );
    		     document.myForm.Name.focus() ;
    		     return false;
    		   if( document.myForm.zip.value == "" ||
    		           isNaN( document.myForm.zip.value ) ||
    		           document.myForm.zip.value.length != 5 ) {
    		     alert( "Please provide a zip in the format #####." );
    		     document.myForm.zip.focus() ;
    		     return false;
    		   return( true );
    	<form name="myForm" action="" onsubmit="return(validate());">
    		<h1>My Form for Lab 11</h1>
    		Type of room: <br />
    		<input type="radio" name="room" value="basic">Basic<br>
    		<input type="radio" name="room" value="luxury">Luxury
    		<br /><br />
    		Activity: <br />
    		<input type="checkbox" name="activity" value="swimming">Swimming<br>
    		<input type="checkbox" name="activity" value="fishing">Fishing
    		<br /><br />
    		Hotel name: <br />
    		<select name="hotelname" multiple="multiple">
    			<option value="-1" selected>Select...</option>
    		    <option value="1">Hilton</option>
    		    <option value="2">Hampton Inn</option>
    		    <option value="3">Holiday Inn</option>
    		<br /><br />
    		Conferee's name:<input type="text" name="name">
    		<br /><br />
    		Conferee's zip code:<input type="text" name="zip">
    		<br /><br />
    		<input type="submit" value="Submit" />
    		<br /><br />
    		<textarea rows="10" cols="50"></textarea>
  2. In Topic: Validate an HTML Form via JS

    Posted 18 Nov 2013

    Ah ok, my apologies. The keyword you said was the focus. I think I know how to tackle it now :D/>...and yes I still need the button it seems
  3. In Topic: Validate an HTML Form via JS

    Posted 18 Nov 2013

    Thanks for the link, but I was trying to avoid just taking code like that but I will use that as a reference if I need to.
  4. In Topic: Validate an HTML Form via JS

    Posted 18 Nov 2013

    Yes we have done basic functions, but to be honest this is the hardest lab we have so far aside from the other topic with the frames. It is a very basic class, but I know how functions work and we have done them for a couple of weeks.
  5. In Topic: Trouble with getElementById

    Posted 11 Nov 2013

    I mean this code works even without the query:

    <!doctype html>
    		<title>Chapter 11, Lab 10</title>
    		<script type="text/javascript">
    			function changeBg() {
    			    if (document.getElementById('color-1').checked==true) {
    		            document.body.style.backgroundColor = 'red';
    		        } else if (document.getElementById('color-2').checked==true) {
    		            document.body.style.backgroundColor = 'yellow';
    		        } else if (document.getElementById('color-3').checked==true)  {
    		        	document.body.style.backgroundColor = 'green';
    		        } else {
    		        	//do nothing
    		<form name="formradio" >
    			<h1>Pick a background color</h1>
    			<input type="radio" id="color-1" name="color" value="red">Red <br /><br />
    			<input type="radio" id="color-2" name="color" value="yellow">Yellow <br /><br />
    			<input type="radio" id="color-3" name="color" value="green">Green <br /><br />
    			<input type="button" value="Click to change the color" onclick='changeBg()'>
    			<input type="reset" >

My Information

Member Title:
D.I.C Head
Age Unknown
Birthday Unknown

Contact Information



Jagst3r15 hasn't added any friends yet.


Jagst3r15 has no profile comments yet. Why not say hello?