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

Reputation: 1 Apprentice
Group:
Active Members
Active Posts:
77 (0.06 per day)
Joined:
21-December 10
Profile Views:
2,174
Last Active:
User is offline Apr 06 2014 06:00 AM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
0
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>
    <html>
    	<head> 
    		<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 );
    		}
    		</script>
    	</head>
    
    	<body>
    
    	<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>
    		 </select>
    
    		<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>
    
    	</form>
    
    	</body>
    
    </html>
    
    
    
    
  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>
    <html>
    	<head>
    		<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
    		        }
    
    			}
    
    		</script>
    	</head>
    	<body>
    
    		<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" >
    
    		</form>
    
    	</body>
    </html>
    

My Information

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

Contact Information

E-mail:
Private

Friends

Jagst3r15 hasn't added any friends yet.

Comments

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