How to redirect with Value and use Option text for Select Input?

Asked

Viewed 43 times

-3

I have a difficulty in Select which is to use Value to complement a link and Select to Input. This is the Select code, as you can see I used Onchange to bring Value to the link:

<select class="div-select" name="cidade" id="cidade" onchange="redirect_to.value=redirect_original.value+this.value" required>
    <option disabled selected>Selecione uma cidade</option><!--Opção em branco-->
    <option value="123456789">Guarapuava-PR</option>
    <option value="123456789">Guiratinga-MT</option>
    <option value="123456789">Igrejinha-RS</option>
    <option value="123456789">Joinville-SC</option>
    <option value="123456789">Lajeado-RS</option>
    <option value="123456789">Otacílio Costa-SC</option>
    <option value="123456789">Panambi-RS</option>
    <option value="123456789">Pinhão-PR</option>
    <option value="123456789">Ponta Grossa-PR</option>
    <option value="123456789">Quedas do Iguaçu-PR</option>
    <option value="123456789">Santa Cruz do Sul-RS</option>
    <option value="123456789">Santa Maria-RS</option>
    <option value="123456789">Santo Ângelo-RS</option>  
    <option value="123456789">São Fidélis-RJ</option>
    <option value="123456789">Teixeira de Freitas-BA</option>
    <option value="123456789">Xanxerê-SC</option>
</select>

And this is the code that redirects to open the Whatsapp link:

<input id="redirect_original" type='hidden' name='redirect_original' value='https://api.whatsapp.com/send?text=Ol%C3%A1%2C%20tenho%20interesse%20no%20curso%20de%20<?php echo $_GET['curso']; ?>.&phone=55' disabled/>

<input id="redirect_to" type='hidden' name='redirect_to' value='https://api.whatsapp.com/send?text=Ol%C3%A1%2C%20tenho%20interesse%20no%20curso%20de%20<?php echo $_GET['curso']; ?>.&phone=55' />

How can I put Value on the redirect link to open Whatsapp and the Option text for the Input from the City field?

  • I didn’t get it right, you want the value of which element and what is the destination of that value? and how do you select it for an input?

  • The inputs "redirect_original" and "redirect_to" they redirect the page, I’m looking for a way to bring the value of select to this input and what is written in the send option in the form action.

  • And this form would be where? Would it be select only? Only inputs ? or all? Type inside the Forms would be select and inputs? Pq you did not put Forms there in the code

1 answer

-3

Try using the Cod below.

        function redirect(){
            cidade  =   document.getElementById("cidade").value;
            form    =   document.getElementById("my_form");
            phone   =   "5511988998899";
            text    =   "Ola, Tenho interesse no curso na cidade de "+cidade;
            link    =   "https://api.whatsapp.com/send?";
            n_link  =   link+"text="+text+"&phone&"+phone;
            console.log(n_link);
            form.action=encodeURI(n_link);
            form.submit();
        }
    <form id="my_form" target="blank" method="post">
        <select class="div-select" name="cidade" id="cidade" required>
            <option disabled selected>Selecione uma cidade</option><!--Opção em branco-->
            <option value="123456789">Guarapuava-PR</option>
            <option value="123456789">Guiratinga-MT</option>
            <option value="123456789">Igrejinha-RS</option>
            <option value="123456789">Joinville-SC</option>
            <option value="123456789">Lajeado-RS</option>
            <option value="123456789">Otacílio Costa-SC</option>
            <option value="123456789">Panambi-RS</option>
            <option value="123456789">Pinhão-PR</option>
            <option value="123456789">Ponta Grossa-PR</option>
            <option value="123456789">Quedas do Iguaçu-PR</option>
            <option value="123456789">Santa Cruz do Sul-RS</option>
            <option value="123456789">Santa Maria-RS</option>
            <option value="123456789">Santo Ângelo-RS</option>  
            <option value="123456789">São Fidélis-RJ</option>
            <option value="123456789">Teixeira de Freitas-BA</option>
            <option value="123456789">Xanxerê-SC</option>
        </select>
    </form>
    <img src="https://www.maisonchique.com.br/images/whatsapp.png"  width="100px" alt="Iniciar Conversa" onclick="redirect()"></body>

when placed on your page, by selecting the city and clicking start chat, it will open a new tab ja with the custom link.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.