i'm using CKEditor to show some text
i have a requirement to prevent editing in some Parts of the text
which will be inserted by JQuery
what i have done
i inserted the input with class so i can change its value
config.extraAllowedContent = 'input(*)';
<textarea name="editor1" id="editor1" rows="10" cols="80">
Some Text <input type="text" id="txttest" class="form-control" style="border:none" />
</textarea>
<script>
var ed1;
ed1 = CKEDITOR.replace('editor1');ed1.on('loaded', function () {
$('.form-control')[0].val('Doctor'); });
</script>
the Problem here i can't find the input $('.form-control') allows return 0 lenght
the second try
var ed1;
$(document).ready(function () {
var data = ' Some Text < input type = "text" id = "txttest" class="form-control" style = "border:none" value = "Doctor" />';
ed1 = CKEDITOR.replace('editor1');
CKEDITOR.instances['editor1'].setData(data)
the problem here the CKEditor render the input as plain text not html
any Help Please
Thank You All
this is the answer for my question for anyone will face the same problem
Thanks to that Post
How to find and replace text in CKEditor using Javascript?
the Code
<textarea name="editor1" id="editor1" rows="10" cols="80">
Some Text.
<input type="text" id="txttest" class="form-control" style="border:none" value="yyy" />
</textarea>
<script>
var ed1;
ed1 = CKEDITOR.replace('editor1');
$(document).ready(function () {
var editor = CKEDITOR.instances['editor1'];
var edata = editor.getData();
var replaced_text = edata.replace("yyy", "iwant this instead"); // you could also use a regex in the replace
editor.setData(replaced_text);
});
Related
Is there a way I can count the number of inputs in a single page?
Say if the page has 5 inputs, a save button will appear- and if there is no inputs on the page, the save button will not appear. How do i do this?
i have this but i dont think this is right
<script>
var x = 0;
var ins = 0;
$(':input').each(function(){
x++;
});
ins = x;
and pass the ins variable to php like
<?php echo '<script>ins</script>';?>
but it doesnt echo anything? is the code right tho
Two line code is enough for you.If you have not any input fields the submit button will be automatically hide.
var inputs = document.querySelectorAll('input');
console.log(inputs);
alert(inputs.length);
if(inputs.length==0)
{
document.querySelector('#button').style.display = 'none';
}
<input type="text" name="name1" value="1111974167" />
<input type="text" name="name2" value="1392666449" />
<input type="text" name="name3" value="1329903177" />
<input type="text" name="name4" value="913532785" />
<button id="button">submit</button>
JS fiddle:
https://jsfiddle.net/njv5e8yc/1/
I am not sure if you actually need to have JavaScript be echoed in php since you can determine count in the first line, but you can not pass javascript to php without ajax. Here is a basic example:
/index.php
<input type="text" name="name1" value="1111974167" />
<input type="text" name="name2" value="1392666449" />
<input type="text" name="name3" value="1329903177" />
<input type="text" name="name4" value="913532785" />
<script>
$(document).ready(function() {
// Get the count of the inputs found
var x = $('input').length;
// Pass the count to php
$.ajax({
url: '/count.php',
data: {
"count": x
},
type: 'post',
// This is what happens with the ajax returns from count.php
success: function(response) {
alert(response);
}
});
});
</script>
/count.php
<?php
if(!empty($_POST['count'])) {
$count = $_POST['count'];
die('The count is: '.$count);
}
You would get an alert dialogue box that says:
The count is: 4
i get recaptcha, put my domain.com.ar and get a key
i use this code
Code.gs
function doGet() {
var t = HtmlService.createTemplateFromFile('Index')
return t.evaluate().setTitle("Contacto de Usuarios").setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename)
.getContent();
}
function processForm(formObject) {
var userCompleto = formObject.userCompleto;
var Email = formObject.Email;
var Movil = formObject.Movil;
var Mensaje = formObject.Mensaje
var captcha = formObject.g-recaptcha-response
var captcha1 = formObject.g-recaptcha
Logger.log(userCompleto+Email+Movil+captcha)
//etc code ........
}
Index.htm
<form id="myForm2" action="?" method="post" >
<input type="text" name="userCompleto" value="" class="ss-q-short" id="userCompleto" size="30">
<input type="text" name="Email" value="" class="ss-q-short" id="Email" size="30">
<input type="text" name="Movil" value="" class="ss-q-short" id="Movil" size="30">
<textarea rows="4" cols="50" name="Mensaje" value="" class="ss-q-short" id="Mensaje" size="30" >
<div id= "example2"></div>
<input type="button" value="Comunicate" id="comunica" name="comunica" style="height: 30px" onclick="validateForm2()" />
</form>
<?!= include('JavaScript'); ?>
JavaScript.htm
<script type="text/javascript">
var onloadCallback = function() {
var widgetId2 = grecaptcha.render(document.getElementById('example2'), {
'sitekey' : '6LeDlhUTAAAAAMbdjlTLHDzA8MMb_pQS6epqgLHs'
});
};
</script>
<script src="https://www.google.com/recaptcha/api.js onload=onloadCallback&render=explicit" async defer>
</script>
<script type='text/javascript' >
function validateForm2(){
//..validation
var objDatosGuardar = document.getElementById("myForm2")
google.script.run.processForm2(objDatosGuardar);
};
</script>
trow a ERROR ERROR: Invalid domain for site key
I try change de key for the captcha and nothing
I try to put in the key new domains like 127.0.0.0
I dont get Looger.log nothing
Please Help
Could you have a look of your environment and check if one of the cases below applies?
Someone seems like solve the same problem by deleting the existing key and reissuing the key.
reCAPTCHA ERROR: Invalid domain for site key
Using reCAPTCHA on localhost: This question below says that there is a possibility that you need to reissue, if you migrated from the V1 to V2.
And one of the comments in this question also suggests you may need to add a different name, not localhost.
I personally used reCaptcha and reCaptchaV2 and never came across this problem, and noticed that I always used a domain name specified by hosts file(/etc/hosts) even if it run in my localhost.
Im so dumb in javascript, I would like to ask your help about radio button validation. I have 3 set of questions, each has 3 radio buttons. I want to validate if all the 3 questions have been answered or checked.
Thanks in advance
Here is the code I have tested, it only validates 1 radiobutton
<script type="text/javascript">
function validateForm() {
var radios = document.querySelectorAll("#option1, #option2, #option3, #option4, #option5, #option6");
var formValid = false;
var i = 0;
while (!formValid && i < radios.length) {
if (radios[i].checked) formValid = true;
i++;
}
if (!formValid) alert("Must check some option!");
return formValid;
}
</script>
I have solved the problem with this code
if ($('div.quizbox:not(:has(:radio:checked))').length) {
alert("You missed answering one or more of the questions.");
}
try this it works for me
<script type="text/javascript">
function validateForm(){
var inputs = document.querySelectorAll("#option1,#option2,#option3,#option4,#option5,#option6")
var formValid = false;
for(var i=0;i<inputs.length;i++){
if(inputs[i].checked){
formValid = true;
}
}
if(!formValid ){
alert("Must check some option!");
}
}
</script>
html code
<body>
<form name="frm">
Question 1<br>
<input type="radio" name="group1" value="Ans1" id="option1">Ans1<br>
<input type="radio" name="group1" value="Ans2" id="option2">Ans2<br>
Question 2<br>
<input type="radio" name="group2" value="Ans1" id="option3">Ans1<br>
<input type="radio" name="group2" value="Ans2" id="option4">Ans2<br>
Question 3<br>
<input type="radio" name="group3" value="Ans1" id="option5">Ans1<br>
<input type="radio" name="group3" value="Ans2" id="option6">Ans2<br>
<input type="submit" value="Test" onclick="validateForm();" />
</form>
</body>
I am used following code hide DataPicker element only hide textbox does not hide image of calender.
HTML Code
#Html.Telerik().DatePickerFor(model=>model.Dateofpublisher)
Jquery
$('[name="Dateofpublisher"]').hide();
You dont need to write DatePickerFor.I always do it as following:
<input id="datepicker" name="date*" type="text" value="" />
*The name of your datepicker should be the same with the name of your model date filed.
And in script codes just write:
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
Note:jqueryui files should be added first.
HTML
<div id="Date">
<input id="datepicker" name="date*" type="text" value="" />
</div>
Jquery
$(document).ready(function () {
$("Date").hide();
});
I have created an iframe-based plugin for CKEDitor using CKEDITOR.dialog.addIframe and want the user to select a radio value, which will be returned to the editor. I am using the code below to try and return the value.
<form name="form1">
<label><input type="radio" name="field_name" value="[value one]" id="field_name_0" onclick="return get_radio_value()" />value one</label><br />
<label><input type="radio" name="field_name" value="[value two]" id="field_name_1" onclick="return get_radio_value()" />value two</label><br />
<label><input type="radio" name="field_name" value="[value three]" id="field_name_2" onclick="return get_radio_value()" />value three</label><br />
</form>
<script language="javascript">
function get_radio_value()
{
for (var i=0; i < document.form1.field_name.length; i++)
{
if (document.form1.field_name[i].checked)
{
var rad_val = document.form1.field_name[i].value;
//alert(rad_val); //this works using onclick
}
}
}
var CKEDITOR = window.parent.CKEDITOR;
var okListener = function(ev) {
this._.editor.insertHtml('<div class="custom_form">'+rad_val+'</div>');
CKEDITOR.dialog.getCurrent().removeListener("ok", okListener);
};
CKEDITOR.dialog.getCurrent().on("ok", okListener);
</script>
I also tried the simple:
var form_value = document.form1.field_name.value;
this._.editor.insertHtml('<div class="custom_form">'+form_value+'</div>');
but this returned "undefined"
Any help or ideas would be appreciated?
Note: Form field values are dynamically created via PHP and fed from a MySQL database.