US>Alert display in javascript

Asked 3 months ago, Updated 3 months ago, 6 views

I'd like to activate the validation alert when I click on the following. How can I do this?Please let me know if you know more.Thank you for your cooperation.

<a href="#"onclick=" document.insert.submit()"id="senddiv">Save</a> 


<form id="form" method="post" name="insert" action="enctype="multipart/form-data">
<input type="text" name="tags" id="tags">
</form>


<script>
$(function(){


    $('#form').submit(function(){

        if($('[name="tags"]US>').val()=='){
            alert("Please enter a tag.");
            return false;
        }

        return true;

    });

});
</script>

javascript

2022-09-30 11:08

2 Answers

I think it would be better to set the onclick attribute value of tag as below.

<a href="#"onclick="$('#form').submit()"id="senddiv">Save</a>

You should now be able to call the event handler that you are working on in JavaScript.


2022-09-30 11:08

If you don't mind using Safari,

<form method="post" action="enctype="multipart/form-data">
<input type=submit value="Save"><br>
<label>tags:<input name="tags" required></label>
</form>

I think this alone will almost accomplish my purpose.JavaScript is not required.


2022-09-30 11:08

If you have any answers or tips


© 2023 OneMinuteCode. All rights reserved.