Reputation: 179
I have a select inside a form with different types of devices from the database (devices.insert.php
):
Type:<select name="type" form="form_select" onchange="showDiv(this)">
<?php
$sql = "SELECT *
FROM Property
WHERE PRP_PRP_TYP_Id = 1";
$result = sqlsrv_query($con, $sql);
echo "<option disabled selected value> -- select an option -- </option>";
while ($row = sqlsrv_fetch_array($result)){
echo "<option value='".$row['PRP_Id']."'>".$row['PRP_Value']."</option>";
}
?>
</select><br>
<script type="text/javascript">
function showDiv(elem){
if(elem.value == 3 || elem.value == 24 || elem.value == 25){
document.getElementById('sc_div').style.display = "block";
}
else{
document.getElementById('sc_div').style.display = "none";
}
}
</script>
And when I select one of the items with the correct id
, a div
element turns visible with more options.
<div id="sc_div" style="display:none">
...
<a href="sim_cards_insert.php">Register new SIM</a><br>
</div>
In sim_cards_insert.php
I have a form with submit and cancel and when I press to go back (to devices_insert.php
) the div sc_div
is not visible again but the data that I've filled before is in the same place.
<button type="button" class="log-btn" onClick="history.go(-1)">Cancel</button>
How can I get it visible again passing through different windows?
Upvotes: 1
Views: 123
Reputation: 945
Sounds like the browser is reverting the DOM to it's initial state - ie with the sc_div
hidden.
Perhaps you could check the previous URL for the devices_insert.php
page load.
<script type="text/javascript">
function showDiv(elem){
//example
var filename = document.referrer.split('/').pop();
if(filename === 'sim_card_insert.php'){
document.getElementById('sc_div').style.display = "block";
}
//...rest of function
</script>
Upvotes: 1