Link to home
Create AccountLog in
Avatar of lateapex
lateapex

asked on

jQuery Mobile button won't submit form

Experts,
MVC 4; jquery mobile

My save button won't submit the form. If I click in a text box and hit enter all is well. There is much chatter about this and I've tried some fixes like replacing the # with %23 but no luck

Here is the submit button and associated script

@section scripts
{
    <script type="text/javascript">
       
        function submitForm() {

            if (document.forms.length) {
                document.forms[0].action = "/RaceData/Edit/@Model.raceNotesId"
                document.forms[0].submit();
            }

            return true;
        }
             
    </script>
}




@section Header
{
    <a href="/Home/" data-icon="back" data-rel="back">Cancel</a>
     <a href="#"  onclick="submitForm();" data-icon="check">Save</a>
    
    <h3>@ViewBag.Title</h3>
    
}

Open in new window



Here's the entire page

@{
 ViewBag.Title = "Edit Race Notes";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@model KartNotes.Models.RaceNotes

@section scripts
{
    <script type="text/javascript">
       
        function submitForm() {

            if (document.forms.length) {
                document.forms[0].action = "/RaceData/Edit/@Model.raceNotesId"
                document.forms[0].submit();
            }

            return true;
        }
             
    </script>
}




@section Header
{
    <a href="/Home/" data-icon="back" data-rel="back">Cancel</a>
     <a href="#"  onclick="submitForm();" data-icon="check">Save</a>
    
    <h3>@ViewBag.Title</h3>
    
}

<form method="post" >
    <div data-role="fieldcontain">
        
          

                 
      
               <textarea  id="raceNotes" name="raceNotes" placeholder="raceNotes"  >@Model.raceNotes</textarea>
                  <!--<input type="text" style="height:100px;" name="raceNotes" id="raceNotes" value="@Model.raceNotes" placeholder="raceNotes" />-->
                
            <label for="raceNotes">Notes</label>

        <input type="text"  name="raceDate" id="raceDate" value="@Model.raceDate" placeholder="raceDate" />
                 <label for="raceDate">Race Date</label>

                
 
       
             </div>
   
    </form>

Open in new window

Avatar of Kyle Hamilton
Kyle Hamilton
Flag of United States of America image

Thats' actually Not the page in its entirety. As it is, the above code works. Something else is breaking it.

Please either provide a link to the page, or post the entire generated html.
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer