javascript - Button redirecting to a different page -
html
<body> <div class="mainwrapper"> <div class="newwrapper"> <form id="newform" method="post" action="new.php"> <div class="textboxcontainer"> <input id="question" type="text" name="question" placeholder="question..." /><br /><br /> <input type="text" name="ans1text" placeholder="answer 1..." value=""/><br /> <input type="text" name="ans2text" placeholder="answer 2..." value=""/><br /> <input type="text" name="ans3text" placeholder="answer 3..." value=""/><br /> <input type="text" name="ans4text" placeholder="answer 4..." value=""/><br /> </div><br /><br /> <div class="doublebuttoncontainer"> <button class="moreanswersbutton" href="javascript:void(0)" name="more_answers" onclick="showallanswers()">more...</button> <input type="submit" class="button" name="submit" value="finish" /><br /> </div> </form> </div> </div> </body> </html> jquery
function showallanswers() { console.log("what going on?????"); $(".textboxcontainer").append("<input type='text' name='ans5text' placeholder='answer 5...' value=''/><br />"); $(".textboxcontainer").append("<input type='text' name='ans6text' placeholder='answer 6...' value=''/><br />"); $(".textboxcontainer").append("<input type='text' name='ans7text' placeholder='answer 7...' value=''/><br />"); $(".textboxcontainer").append("<input type='text' name='ans8text' placeholder='answer 8...' value=''/><br />"); $(".moreanswersbutton").remove(); } for reason, <button> redirecting page. feel might have being inside html post form, have no idea why redirecting when have submit button assigned.
my end result i'm looking more... button add 4 more text boxes form. html editing jquery code.
how can fix issue , make app work properly?
if don't give <button> tag explicit "type" attribute, type defaults "submit". give type="button" override default.
a <button> explicit or implicit type "submit" acts "submit" <input> tag.
Comments
Post a Comment