Jquery / Javascript change form action based on input field

前端 未结 4 951
傲寒
傲寒 2021-01-07 02:51

I have a form like this


    
    
4条回答
  •  轮回少年
    2021-01-07 03:37

    You can do this, you will need to add ids to items. One thing you might want to do is validate the users input.

    HTML

    
      
      
    
    

    jQuery

    $('#myform').submit(function(){
      var car = $('#cars').val();
      $(this).attr('action', "http://www.mysite.com/" + car + ".html");
    }); 
    

    EDIT: It is best to be javascript at bottom of page;

    FULL

    
    
    
      
      
    
    
      

提交回复
热议问题