Solved

jQuery syntax error question

Posted on 2014-12-18
2
123 Views
Last Modified: 2014-12-18
Please look for my comments enclosed within two lines of asterisks:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8" />
	<title>Form Sample</title>
	<link rel="stylesheet" href="normalize.css" />

<!--[if lt IE 8]>
	<style>
		legend {
			display: block;
			padding: 0;
			padding-top: 30px;
			font-weight: bold;
			font-size: 1.25em;
			color: #FFD98D;
			margin: 0 auto;
		}
	</style>
<![endif]-->

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		$("form#myform").submit(function() {
			/*********************************************************

                          WHEN THE NEXT IF-STATEMENT IS EXECUTED, IT SAYS:
                          Syntax error, unrecognized expression: input:#myname

                         *********************************************************/
			if (($("input:#myname").val() == "") || 
			   ($("input:#myemail").val() == "") || 
			   ($("input:#myurl").val() == "")) {	
				return false;
			}
			return true;
		});
	});
</script>

</head>
<body>

<form id="myform" class="group" action="thanks.html" method="POST">
	<fieldset id="login" title="Login Info">
		<legend>Login Info</legend>
		<ol>
			<li>
				<label for="myname">Name *</label>
				<input type="text" name="myname" id="myname" title="Please enter your name" autofocus placeholder="Last, First" />
			</li>
			<li>
				<label for="myemail">Email *</label>
				<input type="email" name="myemail" id="myemail" autocomplete="off" />
			</li>
		</ol>
		<div class="buttonnav next">next</div>
	</fieldset>
	<fieldset id="other" class="hidden" title="Other Info">
		<legend>Other</legend>
		<ol>
			<li>
				<label for="myurl">Website *</label>
				<input type="url" name="myurl" id="myurl" />
			</li>
		</ol>
	</fieldset>
	<fieldset id="comments"  class="hidden" title="Comments">
		<button type="submit">send</button>
	</fieldset>
</form>
</body>
</html>

Open in new window


Can someone please tell me what I'm doing wrong? Thanks.
0
Comment
Question by:elepil
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40507812
Should be

			if (($("input#myname").val() == "") || 
			   ($("input#myemail").val() == "") || 
			   ($("input#myurl").val() == "")) {	

Open in new window


You don't even need the input bit
0
 

Author Closing Comment

by:elepil
ID: 40507883
This was actually part of an example I got that I was studying. Thanks for your help, Gary.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question