Pass as parameter a screen field

Asked

Viewed 34 times

-1

Good afternoon guys, I would like some help. I am new in this area and I ended up taking a project in a methodology that I do not know well yet. I have a project in MVC and needed the following assistance.

On my screen I have a date field and would like to take the content of this date and put as parameter within the same screen on a href. It is possible ? Tela HTML

Below is the field I have with the date on the same page.

inserir a descrição da imagem aqui

  • You can use Javascript in this project?

  • Yes I can use.

  • Come on then, you’ve got id in those fields?

1 answer

1


As you can see I took the value entered in the date field and put as link. The way I did was by focusout(), but you can do by N events. What I recommend is by keycode and focusout()

To see the link, right-click on I am the link and go on inspecting element, see that the href="~/PostoDeServico/ImprimirEscalaPapeleteExecGeral/2020-02-14"

$("#dataInicio").focusout(function(){
  if($(this).val() != "dd/mm/aaaa"){
    var link = $(this).val()
    $(".link_date").attr("href",`${"~/PostoDeServico/ImprimirEscalaPapeleteExecGeral/"+link}`)
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="date" id="dataInicio"><br>
<a href="" class="link_date" id="link_data_1">Eu sou o link</a><br>
<a href="" class="link_date" id="link_data_2">Eu sou o link 2</a><br>
<a href="" class="link_date" id="link_data_3">Eu sou o link 3</a>

In case I don’t know how you need the date, but the default way it comes is: 2020-02-14 For you to modify it the way you want to do the following:

Within the function focusout() I declared the link variable, therefore

link = link.split("-")
link = link[2]+"/"+link[1]+"/"+link[0] //formato 14/02/2020
//OU -------------------->
link = link[0]+"/"+link[2]+"/"+link[1] //formato 2020/14/02
//OU -------------------->
link = link[2]+"-"+link[1]+"-"+link[0] //formato 14-02-2020

Well I hope to help, good luck

  • Great, I will implement and already return with the reply. Thank you so much for now.

  • It was nothing, that this! See you later

  • It worked just right. However how do I have several items href would have to make a loop to change all of them? In the test I made only changed the first one.

  • You can do by class="" then all who are equal will receive the same value!

  • I updated the answer, see if that’s what you imagined

  • Got it? If yes, please put it right, it may be the question of more people

  • Thank you very much. Yes, it did.

Show 2 more comments

Browser other questions tagged

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