I generate a bunch of <div>
with information like this:
@foreach($variables as $variable)
<div id="x1_{{$variable->id}}" value="{{$variable->x1}}"></div>
<div id="x2_{{$variable->id}}" value="{{$variable->x2}}"></div>
<div id="y1_{{$variable->id}}" value="{{$variable->y1}}"></div>
<div id="y2_{{$variable->id}}" value="{{$variable->y2}}"></div>
<div id="page_{{$variable->id}}" value="{{$variable->page}}"></div>
<div id="direction_{{$variable->id}}" value="{{$variable->direction}}"></div>
<div id="variable_{{$variable->id}}" value="{{$variable->variable}}"></div>
@endforeach
Then I want to fill a form when the site is loaded, and whenever the dropdown changes. The dropdown change works, but the fill when it is loaded doesn't. Here is the javascript:
This doesn't work:
$(document).ready(function() {
var drowndown_value = $(this).children(":selected").attr("value");
var x1 = $("#x1_" + drowndown_value).attr("value");
var x2 = $("#x2_" + drowndown_value).attr("value");
var y1 = $("#y1_" + drowndown_value).attr("value");
var y2 = $("#y2_" + drowndown_value).attr("value");
var variable = $("#variable_" + drowndown_value).attr("value");
var regex = $("#regex_" + drowndown_value).attr("value");
var direction = $("#direction_" + drowndown_value).attr("value");
var page = $("#page_" + drowndown_value).attr("value");
$("#x1").val(x1);
$("#y1").val(y1);
$("#y2").val(y2);
$("#x2").val(x2);
$("#page").val(page);
$("#direction").val(direction);
$("#regex").val(regex);
$("#variable").val(variable);
});
This works:
$("#variabledropdown").change(function() {
var drowndown_value = $(this).children(":selected").attr("value");
var x1 = $("#x1_" + drowndown_value).attr("value");
var x2 = $("#x2_" + drowndown_value).attr("value");
var y1 = $("#y1_" + drowndown_value).attr("value");
var y2 = $("#y2_" + drowndown_value).attr("value");
var variable = $("#variable_" + drowndown_value).attr("value");
var regex = $("#regex_" + drowndown_value).attr("value");
var direction = $("#direction_" + drowndown_value).attr("value");
var page = $("#page_" + drowndown_value).attr("value");
$("#x1").val(x1);
$("#y1").val(y1);
$("#y2").val(y2);
$("#x2").val(x2);
$("#page").val(page);
$("#direction").val(direction);
$("#regex").val(regex);
$("#variable").val(variable);
});
I am taking a wild guess and think that:
var drowndown_value = $(this).children(":selected").attr("value");
Is the problem here but I am not sure how to fix it. Any suggestions.