In your example you only use JavaScript. Is this what you want to use? If so, your question is tagged wrong. You also do not specify how the values are stored.
However, you can do this through PHP and it's the route I would have taken.
<?php
if(isset($_GET['id']) && $_GET['id'] != '') {
$id = $_GET['id'];
$values = new ClassThatHandlesValues;
$form_values = array(
'form_id_1' => $values->get($id, 'form_id_1'),
'form_id_2' => $values->get($id, 'form_id_1'),
);
} else {
$form_values = array(
'form_id_1' => '',
'form_id_2' => '',
);
}
?>
<form>
<input id="form_id_1" value="<?=$form_values['form_id_1'] ?>" type="text" />
<input id="form_id_2" value="<?=$form_values['form_id_2'] ?>" type="text" />
</form>
Here, the class ClassThatHandlesValues
might connect to a database or read a file or whatever. It gets the values somehow. If no ID has ben specified, a default array is defined. Here it's empty, but setting some default values might be useful.
Note: This reloads the page. If you don't want to reload the page, JavaSript is the answer and not PHP.