Jump to content

Output php function in JS output


Go to solution Solved by Adamhumbug,

Recommended Posts

I have a function

 

	$(document).on('click', '#newFieldRow', function() {
		console.log('clicked')
		$html = `<div class='row mb-3'>
						<div class='col'>
							<input type='text' disabled class='form-control w-100' name='code[]' value='" . htmlspecialchars($field['Code']) . "' required>
						</div>
						<div class='col'>
							<input type='text' class='form-control w-100' name='label[]' value='" . htmlspecialchars($field['Label']) . "' required>
						</div>
						<div class='col'>
							<input type='number' class='form-control w-100' name='width[]' min='1' max='12' value='" . htmlspecialchars($field['Width']) . "' required>
						</div>
						<div class='col'>
							` + <?php echo (showDataClassifications($pdo, 'select', $field['Classification'])) ?> + `
						</div>
						<div class='col'>
							<select class='form-select' name='type[]' required disabled>
								<option disabled selected value='0'>Please Select</option>
								" . getFieldTypes($pdo, $field['Type']) . "
							</select>
						</div>
						<div class='col-1 text-center'>
						<i class='fa-solid fa-ban'></i>
						</div>
					</div>`

		$('.fieldContainer').append($html)
	})

What is the correct way to get the php in this to execute after it is appended?

Link to comment
Share on other sites

  • Solution

I am sorry all, i am having a bad month.

Below is the answer

 

	$(document).on('click', '#newFieldRow', function() {
		console.log('clicked')
		$html = `<div class='row mb-3'>
						<div class='col'>
							<input type='text'  class='form-control w-100' name='code[]' required>
						</div>
						<div class='col'>
							<input type='text' class='form-control w-100' name='label[]'  required>
						</div>
						<div class='col'>
							<input type='number' class='form-control w-100' name='width[]' min='1' max='12'  required>
						</div>
						<div class='col'>
							<?= showDataClassifications($pdo, 'select') ?>
						</div>
						<div class='col'>
							<select class='form-select' name='type[]' required >
								<option disabled selected value='0'>Please Select</option>
								<?= getFieldTypes($pdo, $field['Type']) ?>
							</select>
						</div>
						<div class='col-1 text-center'>
						<i class='fa-solid fa-ban'></i>
						</div>
					</div>`

		$('.fieldContainer').append($html)
	})

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.