开发者

JQuery Mobile Submit Form

开发者 https://www.devze.com 2023-03-12 19:38 出处:网络
I am trying to submit a form via JQuery Mobile. I have: <form action=\"#pagetwo\" method=\"post\" name=\"myform\">

I am trying to submit a form via JQuery Mobile.

I have:

<form action="#pagetwo" method="post" name="myform">
<input type="text" name="myname">
<input type="submit" value="submit" />

... then I have....

<div data-role="page" id="pagetwo">
...
<?php echo $_GET["myname"]; ?>

The first problem is that it's not doing anything when I hit the submit button. It should go to #pagetwo

What I'm I doing wrong please?

UPDATE:

Here is more code as requested:

<div data-role="page" id="home">

    <div data-role="header">
        <h1>Page 1</h1>
    </div><!-- /header -->

    <div data-role="content">
    <form action="#page2" method="post" name="myform">
    <div data-role="fieldcontain">
        <fieldset data-role="controlgroup">
            <legend>Check Property Elements:</legend>
              <input type="checkbox" name="checkbox-1" id="checkbox-1" class="custom" /><label for="checkbox-1">Yes or No</label>
        </fieldset>
    </div>
    </form>


    ...


    <div data-role="page" data-theme="a" id="page2">
<div data-role="header">
        <h1>This is page 2</h1>
    </div><!-- /header -->
    <div data-role="navbar">
        <ul>
            <li><a href="#home">Home</a>开发者_运维问答</li>
        </ul>
    </div><!-- /navbar -->

    <div data-role="content" data-theme="d">

    <?php if (isset($_POST['checkbox-1'])) {
  // do something with $_POST['value']
  echo 'yessss';

  var_dump($_POST);

}  ?>


First, It is possible that is visible when You hit submit and browser do not scrolls You here (because it is visible).

Try to put some big chunk of something before #pagetwo and see how it goes.

<!doctype html>
<html>
  <head>
  </head>
  <body>
    <form action="#foo" method="get" accept-charset="utf-8">
      <p><input type="submit" value="Continue &rarr;"></p>
    </form>
    <div style="height: 3000px; background-color: #000;">
    </div>
    <div id="foo">Foo</div>
  </body>
</html>

Second, I think You should post you data to different page (or url) not just different anchor.

Third, I see another problem with Your code. Your form says <form method="post" but afterwards You are outputting from get <?php echo $_GET["myname"]; ?>. It should be <?php echo $_POST["myname"]; ?>

0

精彩评论

暂无评论...
验证码 换一张
取 消