0

I have a website with multiple pages using the same form in footer. The footer is included through php, so it's the same on every page. I want to identify the page which message was sent from.

So basically on every page I specify the page-id parameter (thought the would be a good idea?):

<a class="page-id" name="page-a"></a>

then in footer inside the actual form I will get a hidden input field with auto-filled value of "page-a" defined on the actual page:

 <input class="which-page" type="text" value="">

so I want the input to look like this after auto-implenentation of the value:

 <input class="which-page" type="text" value="page-a">

I was trying to use jquery to implement this dynamically, but I'm not very good at it. Here is what I have.

  $pageid = $('.page-id').find('name').clone().text('');
  $('.which-page').find('value').contents().wrap($pageid);

jsfiddle

Thank you

1 Answer 1

1

Use attr() for the name attribute and val() to set value of the <input>

$pageid = $('.page-id').attr('name');
$('.which-page').val($pageid);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a class="page-id" name="page-a"></a>
<input class="which-page" type="text" value="">

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.