javascript - Create a form dynamicaly -
i'm facing issue. have javascript function generates form (using function append()
). i'm trying create form submit button, , when button pressed, php function called, charged stuff. but, it's not working, when press submit button, nothing happens.
though, know code works, because ran on empty project, , without using function append()
.
some question : generating dynamically form using append()
prevents php file called? if does, there way make work? if not, idea why it's not working , how using way?
here javascript code :
function create_user() { var id = document.getelementbyid("right-well"); $(id).empty().append("<h1 class='title'>users</h1>"); $(id).append("<div class='line-title'></div>"); $(id).append("<div class='add-user'>add user</div>"); $(id).append("<form action='../upload.php' method='post' enctype='multipart/form-data'>"); $(id).append("<h4 class='user-name-text'> name :</h4>"); $(id).append("<h4 class='user-mail-text'> e-mail :</h4>"); $(id).append("<h4 class='user-status-text'> status :</h4>"); $(id).append("<h4 class='user-picture-text'> picture :</h4>"); $(id).append("<input class='user-name-input' id='new_user_name' placeholder='name...'></input>") $(id).append("<input class='user-mail-input' id='new_user_mail' placeholder='e-mail...' onblur='check_email();'></input>") $(id).append("<input class='user-status-input' id='new_user_status' onblur='check_status();' placeholder='status...'></input>") $(id).append("<input type='file' class='user-picture-button' id='new_user_picture' onblur='check_picture();'></input>") $(id).append("<button type='submit' name='filetoupload' class='validate-button' onclick='validate_new_user();'>save</button>") $(id).append("</form>") }
ps: php file contains echo "lol";
, testing.
the issue here elements appended after form
element treated siblings of form
, rather children elements. here work around:
function create_user() { var id = document.getelementbyid("right-well"); $(id).empty().append("<h1 class='title'>users</h1>"); $(id).append("<div class='line-title'></div>"); $(id).append("<div class='add-user'>add user</div>"); $(id).append("<form action='../upload.php' method='post' enctype='multipart/form-data'></form>"); var form = $(id).find("form"); $(form).append("<h4 class='user-name-text'> name :</h4>"); $(form).append("<h4 class='user-mail-text'> e-mail :</h4>"); $(form).append("<h4 class='user-status-text'> status :</h4>"); $(form).append("<h4 class='user-picture-text'> picture :</h4>"); $(form).append("<input class='user-name-input' id='new_user_name' placeholder='name...'></input>") $(form).append("<input class='user-mail-input' id='new_user_mail' placeholder='e-mail...' onblur='check_email();'></input>") $(form).append("<input class='user-status-input' id='new_user_status' onblur='check_status();' placeholder='status...'></input>") $(form).append("<input type='file' class='user-picture-button' id='new_user_picture' onblur='check_picture();'></input>") $(form).append("<button type='submit' name='filetoupload' class='validate-button' onclick='validate_new_user();'>save</button>") }
Comments
Post a Comment