转到正文

存档

分类: javascript

It's common that you will be very angry when you have to resubmit a form in case of submiting failure.  So, How to resolve it?

Javascript can do this. There is good article[1] for this problem using Javascript. It's very easy for you to read through and you can also get the resouce code from this article. I just spend 20 minutes to resolve this problem. It's very easy!

Good luck for you!

Reference

[1]. http://www.howtocreate.co.uk/tutorials/jsexamples/saveForm.html
[2]. http://www.megasolutions.net/javascript/Saving-form-values-on-submit-in-case-of-failure-75627.aspx

You are not the only one who has difficulty with line breaks in Javascript. I get a lot of questions about it, so hopefully this will help everyone out. If you come from a ColdFusion background, as I do, I think a lot of confusion comes from the fact that line breaks in ColdFusion are represented by the character 13 (new line character) followed by the character 10 (carriage return character)(ex. "#Chr( 13 )##Chr( 10 )#"). After dealing with this for so long, people instinctively try to replace out the same substring in Javascript text: "\n\r".

The problem is that in Javascript, line breaks are represented by the single new line character "\n", not the combination of new line and carriage return. To prove this, let's create a string in Javascript that uses the new line character "\n" to form multiple line:

var strMultiLineText =
	Karen didn't know how to feel any more. She had never liked girls\n" +
	"\"that way,\" but she couldn't ignore the emotion, that surge of \n" +
	"adrenaline that coursed through her body at the sight of Kimmie's\n" +
	"wet, naked, voluptuous figure in the locker room showers.";

... Let's also create a textarea that has this same string, minus the "\n" characters:

继续阅读

When you create a HTML page, and you press "TAB" key, it's very common that you'll select the next control automatically. This is very useful for users.

However, if you have a textarea control, you may want to write "TAB" key to it, but not use the original function of TAB. So you have to write some javascript codes to make this idea work.

Firsly, you must write a textarea control which has a "onkeydown" function:

<input type="text" id="TextBox_InputYourQueries" name="TextBox_InputYourQueries"  onkeydown="return QueriesInputText(event,this);" Text="" />     

   

You must notice that, we return a javascript function in the "onkeydown" event. And our function is :

function QueriesInputText(oEvent,TextObj) {
    var oTextbox = document.getElementById(TextObj.id);
    if (oEvent.keyCode == 9) {
        oTextbox.value += "\t";
        return false;
    }
}

继续阅读

When you write Javascript, you may want to get client id of which as been clicked. for example,  a span link code can be

<span  id="EditEmail" style=" cursor:hand; text-decoration:underline;" onclick="AlertThis()">Click me</span>

you want to call AlertThis() in your javascript which do something task in this span. As we all know, it's very easy that you can pass the explict client id "EditEmail" to the function. Just like:

<span  id="EditEmail" style=" cursor:hand; text-decoration:underline;" onclick="AlertThis('EditEmail')">Click me</span>

and javascript code can be:

function EmailBox(ElementId) {
       var node_hidden = document.getElementById(ElementId);
}

继续阅读

A best way to change the onclikc event with paramter of Javascript is to use code like:

var node = document.getElementById("span_uploadFile");
node.onclick = new Function( "BatchFile_upload('" + HiddenID_name + "')");

the method of passing by many parameters is similar.

Good Luck!

Reference:

1. http://www.chovy.com/web-development/javascript-dynamically-change-onclick-event/
2. http://stackoverflow.com/questions/748941/setattribute-onclick-and-cross-browser-compatability

For some reasons, I want to use javascript to change the text value of asp:Label control.

A very simple solution is that you can get the client id of server control. You can write javascript in .aspx file as follows:

var Hidden = document.getElementById('<%=this.Label_Hidden.ClientID %>');

"Label_Hidden" is the ID name of your asp:Label.  It means that you get the element object of this control. You can see the asp:Label code :

<asp:Label Visible="false" ID="Label_Hidden" runat="server" Text="" ></asp:Label>

However, if you use a externl javascript method , this way will not work.

继续阅读

www.liaoqiqi.com网站PR查询 博客简洁版 博客Google_Site_Map 博客Baidu_Site_Map ?