2
I have a Django form with this "Linked Exam" field that works as follows: The user clicks on Select Exam, goes to another window in which selects an existing exam, and with it returns to the creation page so that the url informs the exam that was selected (ex: http://127.0.0.1:8000/exam/create?exam_index=23201
indicates that the 23201 exam has been selected and must be linked).
Thus, I would like, when returning to the screen with the selected exam, to display this id in the field (currently, if I type a value and click save works, what is missing and what to fill).
I can also get this id as follows:
var param = /exam_index=([^&#=]*)/.exec(window.location.search);
var exam_id = param[1];
I tried to use "getElementById" but I’m not getting it:
<div class="eight wide field" id="linked-exam-field">
<label> Exame Vinculado</label>
{{form.linked_exam}}
<a id="select-linked-exam" href = "/exam/search">
<i class="add square icon"></i>Selecionar Exame
</a>
<script>
var param = /exam_index=([^&#=]*)/.exec(window.location.search);
var exam_id = param[1];
console.log(exam_id);
//document.write(exam_id);
document.getElementById("linked-exam-field").value = exam_id;
</script>
</div>
How can I do that?
Where is the input with the id
linked-exam-field
? You’re picking up thediv
? I don’t quite understand.– gato
You’re offering too little for anyone to try to help, see if you can create a minimum, complete and verifiable example, making this effort, it is very likely that you yourself solve your problem, ah! take a look at the end of that answer, at the links.
– Sidon