?
Solved

jQuery syntax error question

Posted on 2014-12-18
2
Medium Priority
?
134 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 2000 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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
This article discusses how to create an extensible mechanism for linked drop downs.
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

764 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