nie mogę sobie poradzić z jednym problemem.
Mam na stronie formularz, który jest wysyłany przez <button type="submit">
Jednak pomiędzy znacznikami <form></form> mam jeszcze jeden przycisk <button> tym razem bez żadnego typu tylko z onClickiem. Niestety wciśnięcie go (nawet gdy usunę onClick) powoduje wysłanie formularza :/
Chciałbym by funkcja wywoływana w onClicku zmieniała action="" forma i wysyłała wszystkie dane właśnie tam.
Poniżej kod stronki:
<!DOCTYPE html> <html lang="pl-PL"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="css/style.css" media="screen,projection" /> <script language='javascript' type='text/javascript'> tinyMCE.init({ mode : 'textareas', theme : 'advanced', content_css : './css/tinyContent.css', theme_advanced_toolbar_location : 'top', theme_advanced_buttons1 : 'bold,italic,underline', theme_advanced_buttons2 : '', theme_advanced_buttons3 : '', }); function fileBrowserCallBack(field_name, url, type, win) { var connector = '../../filemanager/browser.html?Connector=connectors/php/connector.php'; var enableAutoTypeSelection = true; var cType; tinyfck_field = field_name; tinyfck = win; switch (type) { case 'image': cType = 'Image'; break; case 'flash': cType = 'Flash'; break; case 'file': cType = 'File'; break; } if (enableAutoTypeSelection && cType) { connector += '&Type=' + cType; } window.open(connector, 'tinyfck', 'modal,width=600,height=400'); } </script> </head> <body> <div class="adminBody"> <div class="topBar"> function addImageToPost(requiredModule,moduleName,sourceID,limitMedia,mediaType) { alert('dupa'); document.forms['newPostForm'].action ='./?page=' + requiredModule + '&source=' + moduleName + '&sourceID=' + sourceID + '&postID=&limitMedia=' + limitMedia + '&mediaType=' + mediaType'; document.forms['newPostForm'].submit(); } <input type='hidden' name='act' value='save'> <div class='postFormContainer'> <input type='text' name='postTitle' placeholder='Tytuł wpisu' required='' value=''> <textarea placeholder='Treść wpisu...' name='postContent' style='width:100%;'></textarea><div class='addImage'><button class='bttn newElement center' onClick='addImageToPost("media","posts",,1,"image");' title='przypisz zdjęcie'>Dodaj zdjęcie reprezentujące<i class='fa fa-plus-circle fa-lg' aria-hidden='true'></i></button></div><button type='submit' class='submit' name='act' value='save'>Zapisz<i class='fa fa-check fa-lg' aria-hidden='true'></i></button> </body> </html>