JavaScript - COMO COMPLETAR CAMPOS DEL FORM SEGÚN URL

 
Vista:

COMO COMPLETAR CAMPOS DEL FORM SEGÚN URL

Publicado por Laude (1 intervención) el 19/04/2017 12:53:45
Tengo el siguiente problema.

En una web tengo un formulario y quiero que me cargue los campos del SELECT según parámetros de la URL.

¿Podéis decirme como hacerlo? Tengo esto de otra web pero no me funciona. Gracias.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$(function(){
	$.urlParam = function(name){
		var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
		if (results==null){
			return null;
		}
		else{
			return results[1] || 0;
		}
	}
 
	var val1 = $.urlParam('cu');
 
	if(val1 == null){
	}
	else if(val1 != null){
		$('#form select[name="dept"]').val(decodeURIComponent(val1));
	}
});
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder