Solved

jQuery syntax error question

Posted on 2014-12-18
2
132 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 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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)

707 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