Issue
I am working on a Django Project and I have the following html page which renders a form. I do not know much of Javascript, and I think I am going wrong somewhere in the Javascript Function or something else entirely. What I need to do is render the "id_mapnubparam01" field only when value of "id_mapnubfunction" is 'GETDATA'. I've split the if condition into 2 just to be clear, the first if condition for the "p" tag works perfectly fine. However using the same if then else logic the "id_mapnubparam01" does not do anything. Any help is appreciated. Thanks.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Data</title>
</head>
<body>
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
{% for field in form %}
<div class="fieldWrapper">
<label>{{ field.label_tag }}</label>
{{ field }}
</div>
{% endfor %}
<input type="submit" value="Submit">
</form>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("id_mapnubfunction").value;
if (x != 'GETDATA') {document.getElementById("demo").innerHTML = "";
} else
{document.getElementById("demo").innerHTML = "You selected: " + x;
}
if (x != 'GETDATA') {document.getElementById('id_mapnubparam01').hide();
} else
{document.getElementById('id_mapnubparam01').show();
}
}
</script>
</body>
</html>
Solution
hide() and show() are jquery function.
If you are running jquery, you'll need to treat the element as a jquery object:
$('#id_mapnubparam01').hide();
if you are not running jquery, try:
document.getElementById('id_mapnubparam01').style.display = "none"
and then set to "block" for show.
Answered By - SamSparx
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.