1

I have xxx.com and six input fields in a page. If user enter values in the input field I want the URL to be like xxx.com/1st value-2nd value-3rd value-etc

Now I am getting the input values in jQuery and passing those values to the URL but I could pass a single value and not all. Here's my code.

$(".search").on("click",function(e){
    // var action = $(this).attr("id");
    var skill = $(":input[name='searchskill']").val();
    var location = $("#searchlocation").val();
    action = skill + "-" + location;
    location.href = action;
    e.preventDefault();
});

2 Answers 2

2

use '/' instead of '-' and get the url parameters in php function like

 function($skill='',$location=''){

 }

and now script will be like

 $(".search").on("click",function(e){ 
    var skill = $(":input[name='searchskill']").val();
    var location = $("#searchlocation").val();
    action = skill + "/" + location;
    location.href = action;
    e.preventDefault();
})
Sign up to request clarification or add additional context in comments.

Comments

2

Try this one

$(".search").on("click",function(e){
    // var action = $(this).attr("id");
    var skill = $(":input[name='searchskill']").val();
    var location = $("#searchlocation").val();
    action = skill + "/" + location;
    window.location.href = action;
    e.preventDefault();
});

EDIT Now I have created plunker for you please edit or suggest what you not getting in it, you also edit that plunker and give me new link to it here is DEMO

2 Comments

Please make sure your jquery actually fetching values by alerting them before passing
@M.Athishkrishna I tried this code running locally, I am sure you are making mistake anywhere in your actual code. Please check once again and if possible provide your actual code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.