Reputation: 82
I am new to javascript and all so pardon me for the mistakes. I am trying to open a pop up for some device discovery. When clicked on the below div,
<div class="ui-grid-solo">
<div class="ui-block-a">
<a href="#waitDiscoveryDialog" data-rel="popup"
data-position-to="window" data-transition="pop"
class="ui-btn ui-corner-all ui-shadow ui-btn-a"
>Discover Device ...</a>
</div>
</div>
it opens a pop up like this
<div data-role="popup" id="waitDiscoveryDialog" data-overlay-theme="b" data-theme="b"
data-dismissible="false" style="max-width:400px;">
<div data-role="header" data-theme="a">
<h1>Device Discovery</h1>
</div>
<div role="main" class="ui-content">
<h3 class="ui-title"
>This will search for new Devices.</h3>
<a href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-b"
data-rel="back">Cancel</a>
<input type="button" data-theme="b" data-inline="true" value="Discover"
onClick="var hi=document.createElement('input');
hi.type='hidden'; hi.name='action'; hi.value='Discover';
settings_form.appendChild(hi);
settings_form.submit();">
</div>
</div>
My requirement is to send the hi.name='action'; and hi.value='Discover' without the input button in the pop up. Because I am using flask framework and there i use this code
if request.method == 'POST':
rf = request.form
try:
action = request.form["action"]
except:
action = ""
if "Discover" == action:
//code for discovering the device
Then close this pop up and open another pop up with a status like "Device found or not found". Can anyone help me to solve this.? Thanks in advance..
Upvotes: 0
Views: 95
Reputation: 6605
As I can see in your code, there is no user input in the popup and you want to submit a static value. If this is the case, why do you even need to open a popup when it is not doing anything?
You can simply write a function triggered on click of button that opens the popup as of now and submit the form.
After submission, you can continue your function to open a popup for "Device found or not found"
For example:
<div class="myPopup">
<h1>This is my popup</h1>
</div>
<style>
.myPopup {
display: none;
position: fixed;
top: 0px;
bottom: 0px;
top: 0px;
bottom: 0px;
margin: auto;
border: 1px solid black;
border-radius: 5px;
height: 500px;
width: 500px;
}
.showPopup {
display: inline-block;
}
</style>
<button title="This will search for new devices" onclick="submitForm()">Discover</button>
function submitForm() {
var hi=document.createElement('input');
hi.type='hidden'; hi.name='action'; hi.value='Discover';
settings_form.appendChild(hi);
settings_form.submit();
}
settings_form[0].addEventListener("submit", function() {
document.getElementsByClassName("myPopup")[0].classList.add("showPopup");
});
Let me know if this helps.
Upvotes: 1
Reputation: 290
Please try
<input type="button" data-theme="b" data-inline="true" onClick="var settings_form= $('formid'); settings_form.submit('Discover');">
Upvotes: 0