JavaScript – different action to same input type but different name

I have a problem with my js script because for both button will open te same site 1. I don’t know why?

Could somebody help me to reslove this problem?


<form id="trackAndTraceForm" target="_blank" class="form-horizontal" enctype="application/x-www-form-urlencoded" method="get" action="">
                                <span>Track and Trace:</span>
              <input type="text" value="" name="numer" placeholder="Numer listu przewozowego"/>                                
              <input type="submit" name="spr" class="btn btn-sm btn-primary" value="Sprawdz"/>
              <input type="submit" name="pod" class="btn btn-sm btn-primary" value="POD"/>


$('#trackAndTraceForm').submit(function (event)
    var val = $('input[name="numer"]', this).val();
    elementClicked = $(;
    var typeBtn = elementClicked.attr('name');

    if(typeBtn == 'spr')

            if(val.substring(0,1) != '0'){
                //console.log('nie zero');
                var action = '';
                $(this).attr('action', action);
                var action = '';
                $(this).attr('action', action);
    else if(typeBtn =='pod'){
        var action = '';
                $(this).attr('action', action);
    else {
        //do nothing;


If I click POD button action is the same like for Sprawdz with url

Source: stackoverflow-javascript

How can I add a delete button to an input display using only javascript?

Okay, before I ask my question, I have searched high and low for this answer and I’ve only come up with no-ended answers or jQuery answers.
I am trying to do this using JAVASCRIPT ONLY. No other libraries.

I know I’m on the right track, but I just can’t figure out how to delete only the last entry of an input that I have created inside a div (all using js).
So, how do I make a delete button actually delete only the input entry it is attached to?

I put my script in a jsbin.
Any help would be greatly appreciated! Thank you in advance! (:

I guess I’m supposed to add my code here anyway so here it is:

<!DOCTYPE html>

Name: <input type="text" id="myText" value="">
Age: <input type="number" name="age">

<button onclick="myFunction()">Try it</button>

function myFunction() {
    var input = document.getElementsByTagName('input')[0].value;
    var agenum = document.getElementsByTagName('input')[1].value;
    var div = document.createElement('div'); = '2px solid red'; = '10px'; = 'block';
    var output = 'Name: ' + input + '
' + 'Age: ' + agenum; div.innerHTML = output; deleteButton(div); } function deleteButton(x) { var del = document.createElement('button'); = 'none'; del.innerHTML = 'Remove this person?'; = 'white'; = 'blue'; document.body.appendChild(del); } </body> </html>

Source: stackoverflow-javascript