Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

jquery form

Posted on 2011-09-06
7
Medium Priority
?
237 Views
Last Modified: 2012-05-12
I have a html form:
==
<form onsubmit="return false;">
  <input type="text" name="phone" size="20">
  <input type="button" value="Phone">

</form>
===
I want to send the value user provided to a function.

$(document).ready(function()  {
   
    alert($("$fieldId").validate());
   
});

==
Can you please provide me the syntex I should have to send the value from that form invoke

    alert($("$fieldId").validate());?

Also I want to get the value from that validate function to be send back to the forum

validate is a Jquery plug in (user defined)
0
Comment
Question by:vkchaitu82
[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
  • 4
  • 3
7 Comments
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 36490394
<<Also I want to get the value from that validate function to be send back to the forum>>
Not sure that you meant

$(document).ready(function() {
    $("#form1").submit(function() {
        $("#txt1").val("123456");

        $("#form1").validate({
            rules: {
                    txt1: {
                            maxlength: 5
                    }
            }
        });
    });
});
0
 

Author Comment

by:vkchaitu82
ID: 36490450
Hi,

As you helped me in the other post:
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_27291256.html

I want to incorporate this to a form.

The Form should have a submit button.
when I submit that , the plug in should be called to validate it.

I was able to get it working with out the form.
But when I insert the form, I am having issue in passing the value from Form to the validate function.
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 36490499
which is what i have suggested...Please try
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vkchaitu82
ID: 36490563
can you give me the syntax in the html page also
<html>
<head>
<title>Checker</title>
<head>
</head>

<body>
<script src ="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"> </script>
<script type ="text/javascript" src="sample.js"></script>
<script type ="text/javascript" src="extension.js"></script>


<form onsubmit="return false; id=form1">
  <input type="text" name="phone" size="20">
  <input type="button" value="Phone">

</form>


</body>
</html>

Open in new window

0
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 2000 total points
ID: 36490637
0
 

Author Comment

by:vkchaitu82
ID: 36519606
Thanks for the links.
Can you please tell me what I am missing.

On submit I am able to call the function I want.
But I am not able to pass the value from Form to function
Please point me to the exact way I can pass the values?

<form id="form1" method="" action="">
  <input id="phone" type="text" name="phone" size="20">
  <input class="submit" type="submit" value="submit"/>

</form>

Open in new window

$(document).ready(function() {
    $("#form1").submit(function() {
        //$("#form1").val("123456");

 
		alert($("#phone").validate1());
    });
});

Open in new window

(function($){
    $.fn.validate1 = function() {
 
      // var str = $(this).val(); 
	   var str = '454550987111';
       var re = new RegExp("^[0-9]{3}[\- ]?[0-9]{2}[\- ]?[0-9]{4}$", "g");
       var myArray = str.match(re);
	   alert(str);
       if ( myArray != null) 
       { 
	     alert("hi");
          return true;
       }
	   alert("no");
       return false;
 };

Open in new window

0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 36520775
if you are talking about how to pass the value of the field to validate method, then uncomment line 4 and comment line 5



0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

618 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