I have to clear selectize input after submit, but it gives me this error message:
Cannot read property 'clear' of undefined
This is what I have so far:
- GET $_POST value, nothing is wrong with this.
<?php
$autoclear = "0";
if (isset($_POST['autoClear']))$autoclear = $_POST['autoClear'];
?>
- My HTML Form, also nothing wrong with this.
<form method="post" action="">
<input type="checkbox" id="autoClear" name="autoClear" value="1" <?php if ($autoclear == '1') echo 'checked'; ?>>
<select id="client" name="client" class="client selectize" >
<option>
...
...
</option>
</select>
<!-- OTHER INPUTS, IRRELEVANT -->
<input type="submit" name="submitBtn" id="submitBtn" class="submitBtn btn-info" value="Submit">
</form>
- This is the problem. It seems like the HTML
<select id="client" .... </select>
must load first before able to call selectize.clear()
function. However, since PHP runs in server side so it will print it out, and maybe that caused the problem?
<script>
function clearSelectize(){
// Clear Selectize [ERROR]
$('#client')[0].selectize.clear();
}
</script>
<?php
if ($autoclear == '1'){
echo "<script>clearSelectize(); </script>";
}
?>
What I initially did: simply reload the page.
<script>window.location.href = 'page.php'; </script>
But this will clear
ALL the inputs, so I have to find a way to clear ONLY selectize input.
Any solution to clear selectize on submit? Let me know if it's a duplicate or if you guys have reference for this.
Any help is very much appreciated! Thanks so much guys!
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment