Add values to a link and open it in the same window on submit

Discussion in 'JavaScript' started by qwikad.com, Mar 28, 2019.

  1. #1
    Let's say I have a link somesite.com/?q=

    I want to add some values to it (via inputs) and open it in the same window on submit. So the link will look like this when it opens: somesite.com/?q=Some Job Title Some Location Some Company Name

    1.png

    It probably should be done via a form with some javascript right? Or how would you do that?


    Appreciate your help!
     
    qwikad.com, Mar 28, 2019 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    You should not do this with client-side processing... you want to combine them to one field, do it SERVER-SIDE.

    You can kind-of cheat though:

    
    <label>City: <input name="q[]"></label>
    <label>Town: <input name="q[]"></label>
    <label>Zip: <input name="q[]"></label>
    
    Code (markup):
    Assuming PHP server-side, you could then just do:

    
    \\ assuming you checked that $_POST['q'] iss set and array first
    $q = implode(' ', $_POST['q']);
    
    Code (markup):
    It's a cute trick, if you have elements named [] PHP will treat them as a dynamic array.

    Again, not something you have any business screwing with using client-side scripting. Do it on the server.
     
    deathshadow, Apr 5, 2019 IP