Saul Ortega Saul Ortega - 5 months ago 20
Javascript Question

How to get back to previous page after HTML form submission

I have this HTML code which contains two HTML forms and two buttons:
One for submit and one for cancel (basically get back to the previous page). What I would like to do is after I click the SUBMIT button and submit my forms do the same as the cancel button (get back to the previous page).
The problem is that I can't specify what page I want it to go back since this page will be used in many pages so it will be dynamic.

<div data-role="page" id="customer" data="Page" data-expired="true" data-theme="c">

<div data-role="content" data="customers" data-key="id" data-params="item:itemid">

<div align="left">
<h3 style="margin:0px">Customer Profile</h3>
</div>

<br/>

<div class="popup-hrule">
<div data-role="collapsible" data-collapsed="false" data-collapsed-icon="false" data-theme="a">
<h3>Customer</h3>
<form id="submit-edit-customer" method="post" data-formaction="process">


<label for="customer_name">Customer</label>
<input type="text" name="customer_name" id="customer_name" data-item=":customer_name">
</div>
<div class="ui-block-b">
<label for="name">Primary Contact</label>
<input type="text" name="name" id="name" value="no valid name"
data-item=":name">
</div>

</form>
</div>

<div data-role="collapsible" data-collapsed-icon="false" data-theme="a">
<h3>Billing</h3>
<form id="submit-edit-customer" method="post" data-formaction="process">


<label for="customer_name">Customer</label>
<input type="text" name="customer_name" id="customer_name" data-item=":customer_name">
</div>
<div class="ui-block-b">
<label for="name">Primary Contact</label>
<input type="text" name="name" id="name"
data-item=":name">
</div>

</form>
</div>

</div>
<a id="createeditcancel" data-role="button" data-inline="true" href="#" data-rel="back">Cancel</a>
<a id="submit-edit-customer-btn" data-role="button" data-inline="true" data-theme="a">Save</a>

</div>
</div>


My question is, is there any easy way to do this without writing a lot of javascript code in the onclick event?

Thanks.

Answer

I didn't know I could do this but I tried it and it worked! I added: data-rel="back" to the submit button.

Like this:

<a id="submit-edit-customer-btn" data-role="button" data-inline="true" data-rel="back" data-theme="a">Save</a>
Comments