M.Athish krishna
M.Athish krishna

Reputation: 227

url formatting using jquery and codeigniter

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();
});

Upvotes: 1

Views: 136

Answers (2)

Sudarshan Kalebere
Sudarshan Kalebere

Reputation: 3937

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

Upvotes: 2

Nagesh Sanika
Nagesh Sanika

Reputation: 1100

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();
})

Upvotes: 2

Related Questions