Textbox is not taking the value that I assign - javascript

I have a page with 10 inputs (TextBox).
I set each input value in the Page_Load with
txtColor.Text = "#FFFFFF"
Each input is a color picker. When the user pick a color, the hexa-name is set in the textbox with a javascript piece of code:
document.getElementById(txtColor).setAttribute("value", newColor);
Buuuuuuut when I try to save the changes I DONT KNOW WHY but the values saved are the old ones.
If at first the value was "FFFFFF" but then the user chose "000000" the program ignores that and save the "FFFFFF" in my db.
I'm working with vb.net
I appreciate any kind of help!
Edit:
Oh god, of course it was the thing that Tim Medora say.
I put the 'Not IsPostBack' and everything works just fine.
Thanks a lot, i wasnt able to see my error.

You say you're using vb script, but your post is tagged javascript. It's not clear what you're working with, but in JavaScript I'd do this:
colorPicker = document.getElementById("color-picker");
colorPicker.addEventListener("change", function () { updateTextBox(); });
textBox = document.getElementById("text-box");
function updateTextBox() {
textBox.value = colorPicker.value;
}
Hope this helps...

Related

jquery change function does not work when fill input from cache

I try do form validator using jquery. Generally everything works except one situation.
I want in any change in input my function checkEmail check is everything is ok. If not color of input is change on red. When i write or paste to input it works but when i choose value from cache (browser give me list of value to choose) my input do not change color.
const checkEmail = () => {
if (!validator.isEmail(emailInput.val())) {
emailInput.removeClass('input-success')
emailInput.addClass('input-error')
return false
} else {
emailInput.removeClass('input-error')
emailInput.addClass('input-success')
return true
}
}
emailInput.change('input', checkEmail);
Is any way to trigger a function on really any change? I event try setTimeOut but then it looks like jquery do not see value in my Input.
PS. Im new here please be patience :)
emailInput.on('input', checkEmail);
here the demo https://jsfiddle.net/kt56opsx/

check box validation javascript

I need to validate the selection of at least one check box on a table. I am not using an alert because I already have a class on CSS that highlights in red the inputs, selects and other elements if they are not filled out.
This is my JS:
var btnRegister= document.querySelector('#btnRegisterRegObr');
btnRegister.addEventListener('click', function () {
var bError= false;
//I am initializing this boolean variable so that it also shows an error
//message on the screen if the user has not selected any option at all...
var elementCheckRegObr = document.querySelector('#checkRegObr');
if (elementCheckRegObr.checked==false){
bError=true;
elementCheckRegObr.classList.add('error');
//This part of the code brings the error I have
//previously created on CSs if the checkbox is not checked
}
else{
elementCheckRegObr.classList.remove('error');
}
});
The button on HTML has the right id on the HTML: id="btnRegisterRegObr.
I was looking at some codes here and people were validating using the .checked==false
However this does not seem to work for mine.
As a matter of fact, I first thought I needed to use the syntax of if (elementCheckRegObr.checked=="") but that one does not seem to work either.
I dont have problems validating inputs, selects nor radio buttons, but I am not sure if I am doing it on the right way with the check boxes. Any help or advice would be greatly apprecciate it :)
I suggest that you use getElementById to get your elements, and test if the checkbox is checked this way:
if(document.getElementById('idOfTheCheckBox').checked){
alert('hey, im checked!');
}

Reset all fields (checkbox, text, select) with <body onload();">

I'm trying to clear all fields on a page but I don't want a reset button. I just want people to hit F5, refresh, etc.
I am trying to use this...
<body onload="MM_preloadImages('../images/PrintButtonWhite.png'); document.CourseMenu.reset();">
to clear my entire form of checkboxes, dropdown menus, and text boxes. It's not working.
Also tried this...
<script type="text/javascript">document.CourseMenu.reset();</script>
Any ideas?
Is CourseMenu the ID of your form? If so, try this:
document.getElementById('CourseMenu').reset();
Assuming you have a Util object. I did this because I use not only trivial html control I use also datepicker and boostrap switches so you have to do it manually. I remove all extra code and let to work with the basic, with this you will have totally control on what are you reseting.. I think you also can send a contair value not a form and will work like a <div> havent tested.
-- Edit --
You can send the continer like Util.resetForm($("#myid")); without caring if it form or other special tag
You can start with this... just use the function on the onload method
try for yourself: http://jsfiddle.net/ncubica/DGMAC/
function reset(objectHTML) {
objectHTML.find("input, textarea,select").not("input[type=submit]").each(function (_index, _item) {
//field is going to evalute ?
if (typeof $(_item).attr("data-ignore") === "undefined") {
switch(_item.type){
case "text":
$(_item).val("");
break;
case "checkbox":
$(_item).removeAttr("checked");
break;
case "select":
$(_item).prop("selectedIndex", -1);
break;
}
}
});
};
$("#test").one("click",function(){
reset($("#myform"))
});
You can add the tag data-ignore="ignore" to dont let the script reset the value this is useful when you dont wan to lose the index of some select
all the select tags will appear on blank after running this script without any selection on it..
//this can be improve with a switch .. but, I'm just showing how can it works..

Using JQuery MaskInput Plugin with a SSN Field

I am trying to use the JQuery MaskInput plugin on a SSN field but I dont see anyway to make it display "***-**-****" after the user leaves the fields.
Did anyone get this working>
I havent tested this, but it may get you headed in the right direction. The masked input plugin has a completed function that can be called when the user has finished entering their value. You can use it to grab the value and store it in a hidden field to retain it and replace the current text with whatever you desire.
var $txt_SNN = $("#txt_SSN");
$txt_SNN.mask("999-99-9999", {
completed: function() {
$('#hdf_SNN').val($txt_SNN.val());
$txt_SNN.val("999-99-9999");
}
});
$txt_SNN.mask("999-99-9999").blur(function() {
$(this).attr('type', 'password');
});`
This should do it. Although I didn't test it.

Need help automate iPhone keyboard input throught javascript

I am trying to automate iPHone UI testing throught JavaScript.
I am in a compose mail page and I need to enter email-id in the TO,CC & BCC fields. I have the focus in TO field and keyboard is displayed. To field is UIATextField, however the usual way of entering data into textfield is not entering the data.
I used the following code
var app = UIATarget.localTarget().frontMostApp();
app.keyboard().elements()["go"].tap();
But did no good for me :(
I want to input the email address(abc#xyz.com) through the displayed keyboard.
Please help me with a code snippet. Also please let me know how to change the focus from "TO" field to "CC" which are one below the other.
The Header, Body buttons on the page are a segmentedControls. I am not able to tap them using the code snippet.
var app = UIATarget.localTarget().frontMostApp();
app.segmentedControls()[0].buttons()["Body"].tap();
Please help me with this.
Thanks in Advance
Kiran
I think you could do this a little better and with some reusability. Try defining a method like this:
function typeCharacters(inputString) {
for(var i in inputString) {
target.frontMostApp().keyboard().typeString(inputString[i]);
}
target.frontMostApp().keyboard().typeString("\n");
}
A quick test of this might look like this:
var timestamp = new Date().toString();
typeCharacters(timestamp);
Then you sit back and enjoy watching the keyboard type out a nice date for you.
Finally figured out how to automate the keyboard tapping
This is the code snippet which worked for me
//Get the keyboard handle
var keyBoard=app.keyboard();
//Get the handle for keys
var keys = keyBoard.keys();
//Get the handle for buttons on the keyboard (Space, Enter, Shift etc)
var keyButtons = keyBoard.buttons();
//To type "hi"
//type "h"
keys.firstWithName("h").tap();
//insert a delay for the tap() action to be completed
target.delay(0.5);
keys.firstWithName("i").tap();
target.delay(0.5);

Categories

Resources