|
Hi everyone
Here is a test page with dynamic function who adds combo box or text box to the form when the user press the + button. There is also a - button who deletes the last box from the list.
In IE when adding value to innerHTML property the changes does not affect previous values, but in Firefox the innerHTML is set to initial state, loosing the user input.
Can anyone tell me if it is possible rewrite this function for Firefox?
<html>
<head>
<script language=javascript>
function ruPanelMultiAdd(sName) {
var sHTML = '';
sHTML = document.getElementById('src'+sName).innerHTML
document.getElementById('div'+sName).innerHTML += sHTML;
}
function ruPanelMultiDelete(sName, sToken) {
var sHTML = '';
var sLower = '';
sHTML = document.getElementById('div'+sName).innerHTML;
sLower = sHTML.toLowerCase();
sHTML = sHTML.substr(0, sLower.lastIndexOf(sToken) );
document.getElementById('div'+sName).innerHTML = sHTML;
}
</script>
</head>
<body>
<form >
<table border='1' align='center' cellspacing='0' cellpadding='0'><tr><td nowrap>
<div id='srcDepartment' nowrap>
<select size='1' name='Department' ID='Department' onblur="this.setAttribute('value',this.value);">
<option value ='14' >Aaaa</option>
<option value ='5' >Bbbb</option>
<option value ='27' >Cccc</option>
<option value ='15' >Dddd</option>
</select>
<br />
</div>
</td><td colspan=2>
<a href="javascript:ruPanelMultiAdd('Department');">[+]</a>
<a href="javascript:ruPanelMultiDelete('Department','<select');">[-]</a>
</td></tr><tr><td colspan=2 nowrap>
<div id='divDepartment'></div>
</td></tr><tr><td>
<div id='srcsGrantor' nowrap>
<input type='text' name='sGrantor' onblur="this.setAttribute('value', this.value);">
<br />
</div>
</td><td colspan=2>
<a href="javascript:ruPanelMultiAdd('sGrantor');">[+]</a>
<a href="javascript:ruPanelMultiDelete('sGrantor','<input');">[-]</a>
</td></tr><tr><td colspan=2 nowrap>
<div id='divsGrantor'></div>
</td></tr></table>
</form>
</body>
|
|
|
|
|
You may have problems if links reload the page when you click on them. Use the onclick event in the links instead, and return false from it to prevent the link to be activated:
<a href="add" onclick="ruPanelMultiAdd('Department');return false;">[+]</a>
(The value in the href property is not used.)
I see another problem with your code also. When you copy the html code of the select element, you will get more than one element with the same id, which is not allowed.
Also, you are replacing all the html code in the div element when you add or remove items. That means that you remove all the elements and then add new elements that are identical, but still they are not the same elements. You might consider it an error that the new elements doesn't get the same state as the old elements, but someone else might consider it an error if they do.
You can use the appendChild and removeChild methods of the div element to add and remove elements inside it. That way you won't be replacing all the elements in it.
---
single minded; short sighted; long gone;
|
|
|
|
|
Thank you Guffa, your answer helped me to the solution.
I will consider changing the link and make the ID's unique, but the appendChild, removeChild and cloneNode did the work I was looking for, this now works in IE and Firefox as I planned.
<html>
<head>
<script language=javascript>
function MultiAdd(sName, iType) {
if (iType == 1) {
var o = document.getElementById(sName);
var e = o.cloneNode(true);
document.getElementById('div2'+sName).appendChild(e);
myElement = document.createElement('<br>')
document.getElementById('div2'+sName).appendChild(myElement);
} else {
var o = document.getElementById('src2'+sName);
var e = o.cloneNode(true);
document.getElementById('div2'+sName).appendChild(e);
}
}
function MultiDelete(sName, sToken, iType) {
var e = document.getElementById('div2'+sName);
if (e.childNodes.length > 0) e.removeChild(e.lastChild) ; // the <input> element
if (e.childNodes.length > 0 && iType == 1) e.removeChild(e.lastChild) ; // the <br> element
}
</script>
</head>
<body>
<form >
<table border='1' align='center' cellspacing='0' cellpadding='0'><tr><td nowrap>
<div id='src2Department' nowrap>
<select size='1' name='Department' ID='Department' onblur="this.setAttribute('value',this.value);">
<option value ='14'>Aaaa</option>
<option value ='5' >Bbbb</option>
<option value ='27'>Cccc</option>
<option value ='15'>Dddd</option>
</select>
<br />
</div>
</td><td colspan=2>
<a href="javascript:MultiAdd('Department', 1);">[+]</a>
<a href="javascript:MultiDelete('Department','<select', 1);">[-]</a>
</td></tr><tr><td colspan=2 nowrap>
<div id='div2Department'></div>
</td></tr><tr><td>
<div id='src2sGrantor' nowrap>
<input type='text' name='sGrantor' >
<br />
</div>
</td><td colspan=2>
<a href="javascript:MultiAdd('sGrantor', 2);">[+]</a>
<a href="javascript:MultiDelete('sGrantor','<input', 2);">[-]</a>
</td></tr><tr><td colspan=2 nowrap>
<div id='div2sGrantor'></div>
</td></tr></table>
</form>
</body>
Joi
|
|
|
|
|
Dear All,
whenever I try to Open New Asp2.0 Application under Http option and try to run that application , browser display error IIS Metabase Error.
Also whenever I hover over toolbox , Statusbar show initialising Toolbox and application hangs .
Develop2Program & Program2Develop
|
|
|
|
|
Check the ASP.NET version of the Application's IIS folder.
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
Hi all,
I'm working on a datgrid that inserts data. But there is a column of name that I want when a user inserts data the user's login name should appear in the column. I'm trying using Windows Authentication But The example I got is not helping me. This is a code on webconfig:
<authentication mode="Windows">
<identity impersonate="true">
<authorization>
<deny users="?">
Where I'm I going wrong?
Thanks
|
|
|
|
|
nclauder wrote: Where I'm I going wrong?
Where is the code of web.config file???
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
Thanks,
The code of web config looks like:
authentication mode="Windows"
identity impersonate="true"
and the Login page looks like on(Page_load):
Response.Write(Page.User.Identity.Name);
Thanks.
|
|
|
|
|
Use the RowDataBound method of GridView to bind the data to row cells.
Here[^] is the sample for how to use RowDataBound.
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
Thanks,
After trying the example I'm getting this mistake While compiling:
The type or namespace name 'GridViewRowEventArgs' could not be found (are you missing a using directive or an assembly reference?)
Thanks.
|
|
|
|
|
i have a session["id"] in c# code behind file, i want to read this session from javascript.
how can i do it
thanks in advance.
haitham
|
|
|
|
|
You can place the value of session["id"] in a hidden textbox in the code behind file. You can access the value of this textbox in javascript.
Wout Louwers
|
|
|
|
|
first thanking for your reply.
if you hide the textbox and then read the value of this textbox from javascript, it is fail , it is succeeded only if the control is visible
i made it using this line document.getelementById("controlid").
thanks
haitham
|
|
|
|
|
Yhis is true if you set the visible property to false. If you set the visisble property to true, and the type property to hidden, it should do the job.
Wout Louwers
|
|
|
|
|
You can assign this to a JavaScript variable and then use it.
|
|
|
|
|
thanks for ur attention to reply me
the problem in accessing variable in code behind file from javascript
thanks.
haitham
|
|
|
|
|
Unfortunately, you can't get js to talk to the server unless you use AJAX....the way to get around it is to use asp:HiddenFields on your page. If you need access to a server side variable, store it in one when you process on the server, then at the client, use document.getElementById to retrieve the value...
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
|
|
|
|
|
hi all
How could i Draw dynamic point Line Polyline polygon on firefox by javacript
same: http://serverx.esri.com/antialiasingexamples/
in Measure
|
|
|
|
|
With more towards Tabbed browsing and popup blockers getting powerful, I just thought there should be a way for us to target our links to open links in New Tab instead of New Window. Basically, at the code level, instead of _blank there should be a way of _blankTab.
Can somebody if come across already, throw some light on it?
|
|
|
|
|
Hello,
I am confucing about the architectures like MVC architecture and 3-tier architecture..can any body help me to clarify my doubts...and which is the best method to follow for asp.net development...
I am waiting for your reply.
Alex.
|
|
|
|
|
in one website, i have created one loging page, after user logged in, page redircts him to the welcome page, this is ok.
problem is here-------
what i want is user should not allowed to come FORWARD after hitting BACK button of the browser. that action must be redircted to the again login page.
so how to identify back and forward button?
regards
krishna
|
|
|
|
|
well make it so that the session is no longer valid after they have viewed the page, then they won't be able to view it again without signing back in.
Brad
Australian
- Christian Graus on "Best books for VBscript"
A big thick one, so you can whack yourself on the head with it.
|
|
|
|
|
Another option is you can compre url such while you are showing the login page first time and after logout you will have the same url. So just compare both if both are same than again put the user on login page.
--------------------------------------------------------------------------------------------------
Hiral Shah
India
If you think that my answer is good enough and can be helpful for other then don't forget to vote.
|
|
|
|
|
I want to use a dropdownlist server control with a datagrid server control sothat when i change the dropdownlist the grid changes but using AJAX. I can do it if the datagrid is a simple html table but i can't implement it if the grid is a server control datagrid. Is there anyway to display the grid as a server control using AJAX or it must be html table to display it with AJAX?
Ahmed
|
|
|
|
|
You can use Anthem.net which is a free librery for ajax controls. it include Combobox, Datagrid etc all have Ajax events, and u dont have to work with JS
http://www.codeproject.com/Ajax/AnthemNET.asp[^]
Nobody is perfect i'm Nobody
|
|
|
|