Question

I have a form which has edit and save buttons switched to make the input box editable and disable.

What I need here is to add a successful message next to the input box.

HTML

<form>
        <label>First Name</label>
    <input type="text" placeholder="Lorem" readonly required  /><input name="Edit" type="button" value="Edit"> <span class="alert">test</span>
        <label>First Name</label>
        <input type="text" placeholder="Lorem" required readonly /><input name="Edit" type="button" value="Edit">
        <label>Email ID</label>
        <input type="email" placeholder="Lorem" required readonly /><input name="Edit" type="button" value="Edit">
        <label>Password</label>
        <input type="password" placeholder="********" required readonly /><input name="Edit" type="Button" value="Edit">
      </form>

Script

$('[name="Edit"]').on('click', function() {
    var prev = $(this).prev('input'),
        ro   = prev.prop('readonly');
    prev.prop('readonly', !ro).focus();
    $(this).val(ro ? 'Save' : 'Edit');
    $(".alert").fade();
});

Here is the fiddle.

This is how I need to show the message when it is saved

enter image description here

Was it helpful?

Solution

Try this:

 $('[name="Edit"]').on('click', function() {

        if($(this).val()=='Save')
        {
        $(".alert").fadeIn();    
        }
        var prev = $(this).prev('input'),
            ro   = prev.prop('readonly');
        prev.prop('readonly', !ro).focus();
        $(this).val(ro ? 'Save' : 'Edit');

    });

OTHER TIPS

Change:

$(".alert").fade();

To:

$(".alert").fadeIn();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top