Solved

jQuery syntax error question

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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…

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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now