JSFIDDLE
I am having trouble letting a user enter their name into a text box and when they click continue it changes another input value for testing reeaons its a textbox but when I put it in my website when its working the input it will be changing will be a hidden value
current javascript
function enterUsername(){
document.getElementById("ign").value = 'test';
};
Your function is only in the local scope. Make it global like this:
enterUsername = function(){...
JSFIDDLE
Related
I am trying to do what seems to be simple but am unable to accomplish
I am trying to set the value of a column after a row focus change in a grid to a hidden value in java script.
My imbedded javascript code:
function OnGridFocusedRowChanged() {
grdA.GetRowValues(grdA.GetFocusedRowIndex(), 'ClientID', OnGetRowValues);
}
function OnGetRowValues(values) {
//Set hidden value
document.getElementById('<%=hdnClientID.ClientID%>').value = values[0];
//Fire button click
btnPopulateGrids_Click();
}
where hdnClientID is the name of my hidden field
In GridA I have the setting as such that OnGridFocusedRowChanged gets executed each time a row focus change takes place.
To this point, it works fine, the values[0] in OnGetRowValues() contains the correct value from the corresponding row in GridA.
But in the corresponding code behind, I cannot access the value from hidden field hdnClientID. Always comes up null when accessing
Current_Client_ID = CInt(hdnClientID.Value);
cannot access or convert any value from
hdnClientID.ClientID.
either.
I'm missing something simple.
I had to complete a similar task recently and I too was unable to access the value from codebehind. I researched and found out that it is not that simple and that you can't do it with javascript. What I would recommend is to check if you have jQuery installed and if you do, change your function to this:
function OnGetRowValues(values) {
//Set hidden value
$('#<%=hdnClientID.ClientID%>').val(values[0]);
//Fire button click
btnPopulateGrids_Click();
//If you change your HiddenField to have OnValueChange event, you can trigger it with this
//__doPostBack('<%= CompanyCode.ClientID %>', '');
}
Also, I guess you are firing some function from code behind with btnPopulateGrids_Click();.
I would recommend adding OnValueChanged="hdnClientID_OnValueChanged"/> to your <asp:HiddenField/> and using my supplied function triggering method.
I have a text field that should be filled before custom saving through HTML custom button.
When a user fills this field and tries to save through custom button, the text inside this field is null even if the user fills it.
Any suggestions Please?
Many Thanks for replying to my query. Actually, I am calling the below function from custom HTML button and I saw the result from alert message as NULL value until I leave the text box. Once I click some other Field then I am getting right value and saving the record successfully. I have posted my code below please have a look and suggest me how I can achieve it. So how to get the text value if a user doesn't leave the text box and click on the Save button?
function createRecord() {
var oDescription = Xrm.Page.getAttribute("new_description").getValue();
if (oDescription != null) {
var callentity = {};
var activityId;
var currentUserId = Xrm.Page.context.getUserId();
var oLeadId = Xrm.Page.getAttribute("new_lead").getValue()[0].id;
callentity.Subject = "Call Activity";
callentity.Description = oDescription ;
XrmSvcToolkit.createRecord({....Some more functions here...
})
}
HTML Button code for calling above function
<input id="SaveCall" onclick="parent.createRecord()" type="button" value="Save Phonecall"></p>
Xrm.Page.getAttribute(arg).getValue(val) won't return a value until focus is lost from the arg attribute (as you've found out).
Some options you could try:
document.getElementById('new_description_i')[0].value
Removing focus from "new_description" on click of your button.
As an exercise for myself I'm trying to make a blog posting application using JavasScript, JQuery and PHP. What I want to happen is that, when you're typing, the title of the page changes. With this, I mean the title declared within the <title></title> tags. A good example of this is StackOverflow: when you're asking a new question, you type in the title of that post, and the page title (the one declared inside the <head>) changes to the title you are typing.
How is this effect done? Is it possible using only JavaScript/JQuery or do you need AJAX for it?
You can just change the title with JS:
document.title = 'New title';
About the effect you are looking for you can probably do something in the lines of:
$(document).ready(function() {
$("input").keyup(function() {
var text = $(this).val();
document.title = text;
});
});
I'm not sure but I think you want to change the page title to whatever is typed in a input tag, For example
something like this?
$(document).ready(function () {
$('#myInput').keyup(function () {
$(document).attr('title', $('#myInput').val());
});
});
the above will track the changes of key up (on keyboard) and get the value of the text input and set it as page title :
here a working fiddle: http://jsfiddle.net/ZLPfM/show
To change the page title, you can do one of two things:
//plain javascript
document.title = 'My JavaScript title!';
//jQuery
$(document).attr('title', 'My jQuery Title');
In order to change it while typing, hook up an keyup event:
$(document).keyup(function(e)
{
//Check the keycode using e.keyCode
});
This will bind it to the document, which means anytime a key is pressed, within an input or otherwise, your event will fire. You could also bind it to a textbox so that it will only fire when you type within the input (which is probably what you want to do).
If you bind to the document, like shown above, you'll have to check the keyCode and append the value onto your title. If you bind to an input, you can grab the input value and set the title to the new value:
$('#myinput').keyup(function(e)
{
var text = $(this).val();
document.title = text;
});
I have several images with the class "red".
When the user clicks on any of them, a form field with the Id of "red" should be incremented.
I'm trying to write this in a way that is easy to re-use.
I can't figure out if there is a way of incrementing the form field value without using a global variable. Simply writing
$(#red).val(++);
doesn't do anything.
If I first declare a global variable like
var redAmount;
$(#red).val(redAmount++);
it works, but I don't like the idea of having to type the color + Amount each time I re-use this for other colors.
Which made me try to form the variable name dynamically like
var redAmount;
var currentColor = $(obj).attr("class"); //getting the class of the clicked element
$('#' + currentColor).val(currentColor+'Amount'++); //trying to form the variable name dynamically but failing
Sorry for the long explanation. What I'm trying to ask is this:
Can I increment the form value without a global variable
If not, how do I form the variable name dynamically based on the class of the clicked element
You can do this with the increment operator in plain-old JavaScript:
document.getElementById("red").value++;
jsFiddle
Code revised with tested sample.
http://jsfiddle.net/webwarrior/CrjY9/25/
Are you not trying to increment the value of item you are clicking on?
jQuery("img").click(function () {
jQuery("#" + jQuery(this).attr("class"))[0].value++;
});
Hope this helps.
This is the true JQuery way, but I guess the JavaScript value++ way is just as good, in some browsers.
I have a texbox inside a templatefield in a gridview. For this textbox I have defined an autocompleteextender with its TargetControlID set to "myTextbox" which is working just fine. At the same time, for the OnClientItemSelected property I have defined a javascript function which should set the value of my textbox, but my question is how can I get the the name of this textbox using javascript?
My control snippet like this:
ajaxToolkit:AutoCompleteExtender TargetControlID="txtValue" onClientItemSelected="SetValue"
And my code looks like this:
function SetValue(sender, eventArgs){
var TitleValue = eventArgs.get_value();
/* do smth with this value */
/* set the new value to my textbox ? */
}
Your suggestions and ideas are very much appreciated. Thank you a lot!
You should be able to get the textbox control using:
sender.get_element()
For extenders, get_element() returns the targeted control, for script controls, it's the element that represents that control.