• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 425
  • Last Modified:

form submission verification on jquery mobile

I have a mobile jquery form. ON submission I check for verification and return false.
It's not stopping the form and I think it has to do with jquery mobile.
How am I supposed to get around it?

<form action="<%=MM_editAction%>" method="post" name="FrontPage_Form1" id="FrontPage_Form1" data-ajax="false" onSubmit="return FrontPage_Form1_Validator(this)">
<input type="submit" name="button" id="button" value="Submit" class="btnplaceOrder" /></form>

Open in new window

Verification looks like this:
  if (theForm.ccf_FirstName.value == "")  {
    alert("Please enter a value for the \"First Name\" field.");
		  $("#accordion").accordion( "option", "active", 1 );

    theForm.ccf_FirstName.focus();
    return (false);
  }
  

Open in new window

0
rivkamak
Asked:
rivkamak
  • 7
  • 5
  • 2
1 Solution
 
Michel PlungjanIT ExpertCommented:
Perhaps post the HTML for the field and include the function statement
0
 
Roopesh ReddyIT AnalystCommented:
Hi,

Sample for you -

 <form>
        <input type="text" name="txt" id="txt" />
        <input type="submit" value="Submit" onclick="return Validate();" />
    </form>
    <script type="text/javascript">
        function Validate() {
            if (document.getElementById("txt").value == "") {
                //Your logic to display custom message
                document.getElementById("txt").focus();
                return false;
            }
        }
    </script>

Open in new window


Hope it helps u...
0
 
Michel PlungjanIT ExpertCommented:
I strongly recommend never to use onclick of submit buttons.
The problem lies elsewhere
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Roopesh ReddyIT AnalystCommented:
Hi,

@mplungjan -
Yeah! I just created a sampe for the author to test. Anyway thanks for highlighting it!!!

@Author

Can you show the complete code to find the culprit.

Moreover, you are using "theForm.ccf_FirstName" , but the form ID is FrontPage_Form1 according to your form tag!
0
 
Michel PlungjanIT ExpertCommented:
That is because the validation passes the form as theForm

function FrontPage_Form1_Validator(theForm) {
.
.
.
0
 
Roopesh ReddyIT AnalystCommented:
Hi,

In that case, it's working fine for me -

    <form action="sample.htm" onsubmit="return Validate(this);">
        <input type="text" name="txt" id="txt" />
        <input type="submit" value="Submit"/>
    </form>
    <script type="text/javascript">
        function Validate(theForm) {
            if (theForm.txt.value == "") {
                //Your logic to display custom message
                document.getElementById("txt").focus();
                return false;
            }
        }
    </script>

Open in new window


Hope it helps u...
0
 
Michel PlungjanIT ExpertCommented:
Why would you mix DOM and form access. You already have the field.  Also return true if ok.

       function Validate(theForm) {
            if (theForm.txt.value == "") {
                //Your logic to display custom message
               theForm.txt.focus();
               return false;
            }
            return true;
        }

There is obviously something else wrong with the page - no need to post similar code to what is already used...
0
 
Roopesh ReddyIT AnalystCommented:
@mplungjan

Aaaah yeah! I didn't noticied it.

@Author
 You need to respond to fix this issue!!!
0
 
rivkamakAuthor Commented:
That script you gave didn't work either.
Is there any connection with the fact that I am using ajax mobile that isn't making that mobile form work?
0
 
Michel PlungjanIT ExpertCommented:
Possibly. Hard to tell with the snippet you sent.

I suggest you debug it

you can use Web Inspector on iPhone for example
0
 
Roopesh ReddyIT AnalystCommented:
Hi,

Are you using any third party plugins? Moreover, try creating a simple page and do some validation and check whether it works.

That way you can narrow down the issue easily!

Hope it helps u...
0
 
rivkamakAuthor Commented:
I made it a simple form with a simple function

  function Validate() {
                          console.log("function running");
                  return false;
        }

the console is logged , but it  doesn't return false. the form still submits.
my button looks like this:

<input type="submit" name="button" id="button" value="Submit" class="btnplaceOrder" onclick="Validate();"/>
0
 
Michel PlungjanIT ExpertCommented:
you need to
Onclick="return Validate()"

But better to do that in onsubmit of the form tag
0
 
Michel PlungjanIT ExpertCommented:
hmm
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 7
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now