-2

I have the following string.

$onclick= " return false;";

And I'm trying to insert it in my HTML code like this.

<input type="checkbox" id="grabados" name="grabados[]" value="no" onclick="return false;">

with this code

<input type="checkbox" id="grabados" name="grabados[]" value="{{ (is_null($partida['grabado'])  ? 'no' : 'si') }}" {{ (is_null($partida['grabado'])  ? '' : ' checked') }} {{ $partida['tipo'] == "otro" ? "onClick = ".$onclick : ""}}>

instead I'm getting this

<input type="checkbox" id="grabados" name="grabados[]" value="no" onclick="return" false;>

When it gets to the space the string is cut

I have tried escape sequences, HTML functions, string functions, everything with no results.

A little help will be appreciated.

miken32
  • 42,008
  • 16
  • 111
  • 154
Arthur
  • 97
  • 1
  • 10
  • You're not getting that, that's what shows up in the inspector, aka what the browser has interpreted. Your problem is that you're not delimiting the attribute. – miken32 Nov 12 '20 at 23:25

2 Answers2

1

This should get closed as a typo shortly, as you've forgotten to delimit the attribute value. In the meantime, here's an example of how to do this while still having readable code:

<input
    type="checkbox"
    id="grabados"
    name="grabados[]"

@if (is_null($partida['grabado']))
    value="no"
@else
    value="si"
    checked="checked"
@endif

@if ($partida['tipo'] === "otro")
    onClick="{{ $onclick }}"
@endif
/>

Also note, if you're creating multiple of these, you are repeating your id attribute, which is not allowed.

miken32
  • 42,008
  • 16
  • 111
  • 154
0

Try This

<input type="checkbox" id="grabados" name="grabados[]" value="{{ (is_null($partida['grabado'])  ? 'no' : 'si') }}" {{ (is_null($partida['grabado'])  ? '' : ' checked') }} {{ $partida['tipo'] == 'otro' ? "onClick = '".$onclick."'" : ""}}>
Ahmed Shams
  • 338
  • 1
  • 9