Hello,
I'm having the problem that whenever I try to use the {{ Form::select('id_x', $x) }} inside my JavaScript the code of the select button is escaped in the view. Like this:
<select name="id_razas"><option value="1">Beefmaster</option><option value="2">Charolais</option>...<option value="9">Shorthorn.20.Jersey.40.Charloais.60</option></select>
function deshabilitar() {
document.getElementById("nombreRaza").innerHTML =
"<table id='tablaRazas'>\n\
<tr>\n\
<td>\n\
{{ Form::select('id_razas', $razas) }}\n\
<input type='number' name='porcentaje0' id='porcentaje0' required style='width: 50px' placeholder='%' min='1' max='99'>\n\
<input type='button' onclick='agregar()' name='plus' style='width: 30px' value='+' placeholder='%' >\n\
</td>\n\
</tr>\n\
</table>";
}
Thank your for your response mkblade,
However when I use the syntax:
{!! Form::select('id_x', $x) !!}
I keep getting this JS error: "SyntaxError: missing ; before statement" in the 'id_x' of my Select.
Just a thought, try switch all single quotes to doubles and doubles to single?
Didn't work. Keep getting the same error. It is possible to use Blade syntax inside JS?
You can, tho I don't recommend doing it. Using Blades means you are likely doing it in PHP file instead. I think keeping .js files by itself will allow better performance since browser stores cache on client's computer to allow quicker access.
The error "SyntaxError: missing ; before statement" is too general for us to tell what has gone wrong. Please check your chrome debugger for further more information.
Just a reminder, in Javascript, you should avoid using straight newline, that sometimes might cause unexpected problems. (It seems to me you might be on that issue. ) Try use string concatenation instead.
Example:
var html = ""
html += "<table id='tablaRazas'>";
html += "<tr>";
// blah blah blah....
document.getElementById("nombreRaza").innerHTML = html
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community