V
V
Vladimir2017-03-13 12:17:04
JavaScript
Vladimir, 2017-03-13 12:17:04

How to write value to value using jQuery or JS?

Hello. Site on Bitrix. I have a feedback form like this:

<form action="/send.php" method="POST" enctype="multipart/form-data" name="form" id="form">	
      <input type="hidden" name="element" value="<?=$arResult["ID"]?>">
      <input type="email" name="email" placeholder="E-mail" value="" required>
      <input type="text" name="textarea" placeholder="Текст сообщения" value="">
      <input class="submitbutton" name="" type="submit"  value="Отправить">   
</form>

it sends the file to the mail using the POST method. Depending on the value of $arResult["ID"] the file to be sent changes.
Right now this form is in a catalog component in the template.php file
. I need to put it in the footer. To do this, I need to pass the value of $arResult["ID"] to this same value. I think this is possible with JS. I don't know the syntax well. So far I have written this in template.php
<script>
$('.form').click(function() {
  $('.form').find('input').val('<?=$arResult["ID"]?>');
  $('.form').find('element').val('<?=$arResult["ID"]?>');
  return false
}); 
</script>

does not work. Tell me how to write correctly.
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
IgorRastarov, 2017-03-14
Portev @Vladimir Portev

Do you have a static form? Does it just show up on the page or is it made as a popup window?
If it is like a pop-up window, then you can attach a function to the button that is responsible for opening this form. For example, so
And this is the function that you need to write in the file where all the scripts are written.

function test(id){
  $("input[name=element]").val(id);
}

I
Igor Peregudov, 2017-03-13
@igorperegudov

$('.form').find('input[name="element"]').val();
like this search by "name"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question