|
</code>Hey,
I am trying to create multiple jscript input fields, once a user clicks on a button.
Basically the click on a button and a new set of input fields is added (many of these could be made, its the users discretion.)
Im having problems.
here is some of my code.
<code>
<script>
var cfields= new Array();
var x = 0;
function showFields()
{
var divID= 'results';
var output='';
output+= '<div style="border: 1px solid; width: 151px;padding: 3px;" id="announcements"><input type="text" value="URL"><br>'+
'<input type="text" value="Headline"></div>';
output+='';
document.getElementById(divID).innerHTML = output;
}
///////////////////////////////////////
//
//////////////////////////////////////
function newField()
{
var foo = new showFields();
cfields.push(foo);
alert(cfields);
x++;
}
</script>
<body>
<!--<a href="#" onClick="showFields();">Click here</a>
<a href="#" onClick="newField();">new Field</a>-->
<br /><br />
<table>
<tr>
<th><p>Email Generator</p></th>
</tr>
<tr>
<td>
<div style="border: 1px solid; width: 151px;padding: 3px;"><input type="text" value="Date"></div>
</td>
</tr>
<tr>
<th align="left"><p>Announcements</p></th>
</tr>
<tr>
<td>
<div style="border: 1px solid; width: 151px;padding: 3px;" id="announcements'+x+'"><input type="text" value="URL"><br>
<input type="text" value="Headline"></div>
<div id="results"></div>
</td>
<td valign="top">
<div style="border: 1px solid; width: px;padding: 3px;" align="center"><input type="button" value="+" onClick="showFields();"><br>
<input type="button" value="-"></div>
</td>
</tr>
</code>
I tryed to create a new array and stick a new instance of the function into it.
This is not working. Someone please help me.
|
|
|
|
|
<html>
<head>
<script>
var d=document;
var fldArray=new Array();
var IDcount=0;
function Field(){
this.fldID=0;
this.fldObj=0;
this.isAppended=0;
//Methods
this.CreateField=GCreateField;
this.AppendField=GAppendField;
}
function GCreateField(){
var newFld=d.createElement("DIV");
newFld.id="announcements"+IDcount;
IDcount++;
newFld.className="cFld";
newFld.innerHTML="<input type=\"text\" value=\"URL\"><br>"+"<input type=\"text\" value=\"Headline\"><br>";
this.fldID=newFld.id;
this.fldObj=newFld;
}
function GAppendField(parentID){
if(!this.isAppended){
var parentObj=d.getElementById(parentID);
parentObj.appendChild(this.fldObj);
this.isAppended=1;
}
}
function GAddField(){
var newFld=new Field();
fldArray.push(newFld);
window.defaultStatus=fldArray.length;
}
function GShowField(index){
if(fldArray[index]!=undefined){
fldArray[index].CreateField();
fldArray[index].AppendField("results");
}
}
</script>
<style>
.cFld {
}
</style>
</head>
<body>
Content:<br>
<div id="results"></div>
<input type="button" value="+" onClick="GAddField()"><br>
<input type="button" value="-">
<input type="button" value="Show 0" onClick="GShowField(parseInt(d.getElementById('fldInd').value))">
<input type="text" value="index to show" id="fldInd">
<!-- If the Status shows 5 the last index is 4.
</body
</html>
I hope this helps.
|
|
|
|
|
Hey thanks for that script, I do appologize I have not used it, I sort of already created my own, using DOM as well.
here is what I have:
<code>
<html>
<script>
var annouceInputs = 1;
//////////////////////////
//Creates new announcement
//////////////////////////
function addAnnounce()
{
var table = document.getElementById('annoucementData');
var tr = document.createElement('TR');
var td2 = document.createElement('TD');
var td3 = document.createElement('TD');
var inp1 = document.createElement('INPUT'); //url for announcement
var inp2 = document.createElement('INPUT'); //headline for announcement
var breaks= document.createElement('br');
var inp3 = document.createElement('INPUT'); // delete "-" button
var p1 = document.createElement('p');
var p2 = document.createElement('p');
var inp4 = document.createElement('INPUT');
var break2 = document.createElement('br');
if(annouceInputs>0)
{
var img = document.createElement('IMG');
inp3.setAttribute('type', 'button');
inp3.setAttribute('value', '-');
inp4.setAttribute('type', 'button');
inp4.setAttribute('value', '+');
p1.className='delete';
inp1.className= 'delete';
inp2.className= 'delete';
td3.appendChild(inp4);
td3.appendChild(break2);
inp3.onclick = function()
{
removeElement(tr);
}
inp4.onclick = function()
{
addAnnounce();
}
td3.appendChild(inp3);
}
inp1.setAttribute("name", "announceUrl"+annouceInputs);
inp1.setAttribute("value", "URL"+annouceInputs);
inp2.setAttribute("Name", "annouceHeadline"+annouceInputs);
inp2.setAttribute("value", "Headline"+annouceInputs);
table.appendChild(tr);
td2.style.paddingLeft = "50px";
tr.appendChild(td2);
tr.appendChild(td3);
td2.appendChild(inp1);
td2.appendChild(breaks);
td2.appendChild(inp2);
annouceInputs++;
}
//////////////////////////////
//Removes the new Child element
//////////////////////////////
function removeElement(tr)
{
tr.parentNode.removeChild(tr);
}
</script>
<body onload="addAnnounce();" >
<br /><br />
<FORM NAME="myform" ACTION="#" METHOD="GET">
<table>
<tr>
<th><p>Email Generator</p></th>
</tr>
<tr>
<td style="padding-left: 50px;">
<input class="delete" type="text" name="date" value="Date">
</td>
</tr>
<tr>
<th align="left"><p>Announcements</p></th>
<td valign="top">
<input type="button" value="+" onClick="addAnnounce();">
</td>
</tr>
<tr>
<tbody id="annoucementData" valign="top" border="1">
</tbody>
</tr>
</table>
</FORM>
</body>
</html>
</code>
Now you can put that into a temp page and see waht it actually does.
The problem that I am Having now, is that I dont know how to collect the data if
someone were to actually fill out the input boxes. (lets say they fill out 4 sets)
How do I collect the data?
Please help, and thanks
Wally
|
|
|
|
|
Well it depends when you want to collect the data. Basicly you need
to asign an id to the two input fields, but that you already know.
You may want to post it to some server side script or to do something
with the data in the JavaScript. You may want to collect it when some internel(for the announcement) event occurs. Then it's better to implement the event
handler in a DOM class and each item handles it self. Or you can declare
a global array to keep the fields in it( the whole object or just the
field ids).
If you have their ids you can easily collect the data and do whatever you want with it.
|
|
|
|
|
|
Is it possible for a non admin user to create virtal dirs/administrator iis? If yes how?
Thanks
Dinuj Nath
|
|
|
|
|
|
I believe elements have an onmouseover property that you can call a javascript function for...I've used it to set the window.status when someone's cursor hovers over an element.
I've also done something similar to this by setting the style of an html cell. You can set this: Style="Cursor:Hand" to make the cursor turn into a hand whenever it is on this cell.
Hope this at least points you in the right direction.
|
|
|
|
|
hello there...
Suppose i already have some web pages under the following, www.blablabla.com, and i want to update some data or modify some menus, add some texts, so how am i going to do so? wat methods?
Any help and iam thanksfull.......
scorp_scorp
|
|
|
|
|
Please ask specific problems and also in a bit detail.
Best Regards,
Apurva Kaushal
|
|
|
|
|
well, details , mmmm lets seee........
Suppose i created a website (# of webpages) , i gave it for certain company to host it and load it, so, so its www.adc.com, then i wanted to add another item in a certain menu in the first page, or i want to change certain text in a page (Welcome ALL ) to (hey every body), so how i can do this, shall i go to them, nock the door, go insidem, open the pages, adjust them and save, ofcourse not...
Hope i explained in details, thanks Apurva Kaushal, waiting ur answer.
scorp
|
|
|
|
|
No ofcourse not in that way. But to change anything you need to know how exactly they are being displayed. What technology they have used to create the site. Whether it asp.net, plain html page or what.
Best Regards,
Apurva Kaushal
|
|
|
|
|
mmmmm ok dude, thanks alot.
scorp
|
|
|
|
|
always welcome..
Best Regards,
Apurva Kaushal
|
|
|
|
|
how can i apply 'bold' as style to the selected text of label control.
The applied 'bold' to the selected text should remain even after some navigation to the other pages in the application.
kamalnath
|
|
|
|
|
How to make a textbox not accept certain words?
Example : can not contain word "dog" in a string
I hv tried negative lookahead (?!regexp) and many other method i found through google, but none of them work. I'm using RegularExpressionValidator in VS 2003. Izzit related?
-- modified at 2:01 Wednesday 27th September, 2006
|
|
|
|
|
|
Anyway, Thx for your help.
But i'm quite new to regular expression. I still not sure what to put. Appreciate if someone can give me the solution. Thx
|
|
|
|
|
It depends what exactly you want your user not to put in the textbox. I hope it won't be "dog" as you mentioned.
Best Regards,
Apurva Kaushal
|
|
|
|
|
haha, it just an example.
Finally i found the solution.
^((?!(illegal)).)*$
but regular expression is case sensitive. that's mean words like "illegAL" will not work... i think i better use back the .net code... anyway, thx ..
|
|
|
|
|
|
Hi there
guess this is a helpful link
[^]
it contains many useful information about regular expressions.
Best Regards
3ala2
|
|
|
|
|
Hi,
In our asp.net 1.1 application client has told us to maintain one session per application means only one user can login at a time and if another user tries to login then we should tell that user that another user has already logged in. So all these things i finished doing but i am facing a problem when user closes the window directly without bieng logging out and the default session timeout is about 20 minutes so if a user has closed the window another user cannot login for another 20 minutes till the session expires.
So to avoid this using javascript i have written a function which will execute onbeforepageload event which will post to the login page with a querysting parameter which tells that the user has clicked the logout button and i am ending the session of that user. This is working fine for the close window but also it is getting executed when we refresh the page. through some javascript coding i got succeede to avoid the F5 refresh but we have to avoid even others options of refresh also. and we cannot disable those options.
hope you have understood my problem. So can anybody please help in this matter how to solve this problem.
Thanks in advance
Syed Saleem
|
|
|
|
|
The easiest way what I feel is to use Meta information and get the trick working. Consider we have a page WebPage.aspx add the below code in the the WebPage.aspx.cs file.
private void Page_Load(object sender, System.EventArgs e)
{
Response.AddHeader("Refresh",Convert.ToString((Session.Timeout * 60) + 5));
if(Session[“IsUserValid”].ToString()==””)
Server.Transfer(“Relogin.aspx”);
}
In the above code, The WebPage.aspx is refreshed after 5 seconds once the Session is expired. And in the page load the session is validated, as the session is no more valid. The page is redirected to the Re-Login page. Every post-back to the server will refresh the session and the same will be updated in the Meta information of the WebPage.aspx.
|
|
|
|
|
Thank you very much for your reply and sharing your precious time in solving me problem. Please see the description below what actually i am doing in the code and help me.
Actually when the user closes the window(browser) directly without logging out i am killing the user session by executing a javascript function as follows:-
var code;
function getKey(keyStroke) {
// keycode for F5 function
if (window.event && window.event.keyCode == 116) {
//window.event.keyCode = 8;
code=window.event.keyCode;
return true;
}
}
function closeIt()
{
if (code != 116)
{
window.location.href="Default.aspx?action=logout";
}
}
the above javascript function im calling by the following way:-
as when the window will be closing onUnload event and onbeforeunload events will be fired, so in onbeforeunload event i am calling a function CloseIt() which will set the location reference of the page to the Default.aspx which is an login page and there i am checking for the querystring parameter "action" with the value "logout" then i am killing the users session. But the problem is that the onbeforeunload and onunload events will be fired even when we refresh the page. Some how i got succeede to avoid the F5 key as u can see the code above by taking the key of F5 key.
i have already added the line of code you have mentioned:
Response.AppendHeader("Refresh", Convert.ToString(Session.Timeout * 60) +"; URL=Default.aspx?action=logout");
the above line of code will redirect the page to the login page automatically when session expires.
But my problem here is to kill the user session when the user closes the window without logging off and when i am trying to kill the session in the onbeforeunload event of javascript it is even killing the session when we refresh.
So please help me in this how can i over come this problem. Is there any javascript event which will distinghiush window close and refresh. if any please let me know.
Thanks in Advance
Syed Saleem
|
|
|
|