0

I have a jobs website with several different job description pages and with 1 application page with a form.

i.e.

/admin-clark -> /application
/sale-rep -> /application

I would like to pre-populate an input field in the form with the id #jobTitle.

I would like to do the following-

  • Get the previous URL
  • Store it in local storage
  • Sanatize url(remove dashes etc)
  • Use jQuery to fill in the field with id jobTitle

Or is a there a better way of doing this?

This is what I have so far

var pathname = window.location.path.replace(/^\?$/, '').toUpperCase();
localStorage.setItem("pathname ", pathname );
$('#jobTitle').val(pathname);
Dan Mitchell
  • 844
  • 2
  • 15
  • 34
  • 1
    Why not pass through a reference to the application page of the page they came from? Something like :`application.php?job=admin-clerk`. – BenM Jul 24 '14 at 08:20
  • please describe your question. what you want to pre-populate and when? What is #jobTittle? and what is relation of previous url ? – Mahipat Kanzariya Jul 24 '14 at 08:23
  • @BenM, that's a good idea, how would I append this string to the url? – Dan Mitchell Jul 24 '14 at 08:51

1 Answers1

2

in many cases(Not in every case) will get you the URL of the last page if they got to the current page by clicking a link using document.referrer; See here

You can also take help from here

Community
  • 1
  • 1
Roshan
  • 2,144
  • 2
  • 16
  • 28