|
I am a programmer with a little networking knowledge (enough to get by). You probably get a useful response from a non-programming discussion board.
|
|
|
|
|
All help is greatly apporeciated..I am in the same boat as you...
Jude
|
|
|
|
|
I'm trying to do some form validation that involves looping through all elements in a form. It works perfectly in FireFox, but totally chokes in IE7. It seems to be that the $Form.elements.length value is not returning a number.
I've written a little test function to simulate the error.
<br />
function validateForm()<br />
{<br />
alert(document.forms.length);<br />
var numElements = document.forms[0].elements.length;<br />
alert(numElements);<br />
}<br />
First alert shows: 1
Second alert shows: [object]
Anyone seen this happen before?
Thanks a lot.
|
|
|
|
|
try something like this
function checkForm()
{
var frm = document.getElementById('form1');
var strError = 'The following fields are required:\n';
var bValid = true;
var child;
for(var i = 0; i < frm.childNodes.length; i++)
{
child = frm.childNodes.item(i);
if(child.nodeType == 1)
{
if(child.tagName.toString().toLowerCase() == 'input')
{
if(child.type.toString().toLowerCase() == 'text')
{
if(child.value == '')
{
strError += '\n'+ child.id.toString();
bValid = false;
}
}
}
}
}
if(!bValid)
alert(strError);
return bValid;
}
Works in both FF and IE7. It only checks input text's at the moment so you'll need to change it so that it's a bit more useful, but it should get you going.
HTH
|
|
|
|
|
Thanks very much for the reply, but I guess my main question here is why $Form.elements.length is not returning a number. This has always worked before....
|
|
|
|
|
Wierd, just done a tiny test myself using your code and get a number as you'd expect from elements.length
Here is the code I ran:
<form id="form1" name="form1" onsubmit="return checkForm();">
<input type="text" id="Text1" />
<input type="text" id="Text2" />
<input type="text" id="Text3" />
<input type="text" id="Text4" />
<input type="submit" />
</form>
<script>
function checkForm()
{
alert(document.forms.length);
var numElements = document.forms[0].elements.length;
alert(numElements);
return true;
}
</script>
The first alert gives "1" and the second gives "5". If your form isn't too huge perhaps you could paste in the code that's giving you this wierd behaviour.
HTH
|
|
|
|
|
Well, I feel dumb now. I had a textbox in the form named "length".
Thanks for all your help.
|
|
|
|
|
hehe - one of those
|
|
|
|
|
I guess let me give you a bit of background...I am developing a image gallery for a website. From a main page the user chooses an Album which sends them to the ViewAlbum.aspx. On the ViewAlbums.aspx page there is an image control <asp:image id="imgCurrent" ...=""> which defaults to the first image in the album. To the right there are thumbnails of each image in the album.
What I am trying to do is have the user click on the image thumbnail and have it update the imgCurrent.ImageUrl property (and have the picture they selected then show in the Image control). I have literally been at this for hours and it's just getting ridiculous. Has anyone done something like this (I can't imagine it's not common practice).
ANY help would be greatly appreciated!
Thanks again!
John
|
|
|
|
|
Is this not an ASP.NET question ?
Surely you're saying that you have thumbnails, which generate a postback, and then an event handler which sets this URL ?
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I put it in the general web development because I thought I might need to use some javascript scripting to get it done. I've tried so many things without any luck, I thought maybe different perspectives is what I need.
Yes, I have thumbnails. Having them generate a postback that I can access my codebehind functions from has been my problem and is where I'm looking for some guidance.
Thanks Again!
|
|
|
|
|
I did a quick google, and it doesn't look like the asp:Image tag has an OnCLick event. I could be wrong there, I expected it would. If it does, then you just need to wire that up. If not, you can pass an onclick through to the client, just have it return to the same page, but pass the id of the image on the URL.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
I was hoping not to have to do that, but I guess if it's the only way, it's the way I'll have to do it.
Thanks for your help!
|
|
|
|
|
Could you use an ImageButton instead?
|
|
|
|
|
How do you mean? Use an ImageButton as the main image or as the thumbnails?
I'm guessing you mean as the thumbnails. In which case my question would be, can I create them at run time and give them a function to call where I can pass parameters?
|
|
|
|
|
Well this is what I ended up doing. I think it is along the lines of what Paddy had suggested...
<img alt="" src="<%=GetImageThumbnailUrl(drimage.Item("ImageId")) %>" onclick="javascript:window.location.href='ViewAlbum.aspx?AlbumId=<%=sAlbumId%>&CurrentImage=<%=drimage.Item("ImageId")%>'"/>
It works but I don't like that the whole page has to reload. I guess that's the only way to do it, if anyone knows of a better way to do this than what I ended up doing then please let me know!
Thanks to ALL of you who helped soooo much!
Thanks again!
|
|
|
|
|
Hello,
does anyone know if it possible to read data from a javascript form and write it into a database (Access for example)? I have an online form that i used with cgi-mail and now i need to save the info on a database, any help would be appreciated...
Thanks
Rona
|
|
|
|
|
JavaScript should never directly communicate with a database because then the user would be able to see the passwords etc for it.
What you should do is have it call a PHP/ASP page that will do the database work for it.
Brad
Australian
By contacting your lawyer you negate the right to sue me.
|
|
|
|
|
JavaScript is a scripting language that runs inside the browser and stays inside the browser. JavaScript can't be made to access anything external on the users computer, such as files on the users hard drive, or change settings on the users computer. If it did it would constitute a major security risk.
So basically what you're asking is impossible, you can't access a database directly but, as the other poster says, you could do it indirectly via a server side script in ASP/PHP etc, but it would have to be a database on the server and not on the users computer. You could get JavaScript to initiate a page post back, or use Ajax to call a server side ASP.NET page which connects to the database.
|
|
|
|
|
Yes it is possible, but unless you really really really need to (and even if you think you need to you probably don't and you certainly shouldn't) then don't.
var objConn = new ActiveXObject('ADODB.Connection');
var objRs = new ActiveXObject('ADODB.Recordset');
objConn.Open(conn_string);
objRs.Open('SELECT * FROM table', objConn, 2, 3);
if(!objRs.BOF)
{
objRs.MoveFirst();
while(!objRs.EOF)
{
document.writeln(objRs.Fields("title").Value +'<br/>\n');
objRs.MoveNext();
}
} It will work, but you will have to have extremely low security settings in IE (it will only work in IE). The user will also get a couple of security warnings which you can't get rid of. The above is provided merely as evidence that it is possible, if you haven't got the hint yet then I'll say once more.... please don't use this for anything other then learning.
As you're using cgi-mail, you obviously have access to some server-side technology so use that for communicating with your DB.
HTH
|
|
|
|
|
it will only work in IE
So for all intents and purposes, it doesn't work
|
|
|
|
|
Are there any such editor that you can recommend from your experience. I need to be able to introduce my custom objects in it for user to drag and drop. Like custom images and stuff. That's is how I need it to be customizable.
My application is a dynamic content capture tool. Admin folks define the fields in the system and also define the layout. It's the layout part that I need the HTML Editor for. All the fields need to be identifiable in the editor. So Admin User should be able to drag and drop Name and Age fields etc.
Thanks
|
|
|
|
|
|
I wish test if some client side file exists, like swf, jpg, gif, css, etc. Do you know some method to test this?
Regards
-- modified at 17:36 Wednesday 29th November, 2006
Sample:
If one image does not exists, the IE shows a red X icon. I wish with javascript, test if the image does not exists, simply to set css style to hide the image, then this red X icon will not appears.
-- modified at 17:36 Wednesday 29th November, 2006
Jesus is Love! Tell to someone!
|
|
|
|
|
Well I just hacked this together off the top of my head so it may/may not work properly, but it should get you pointed in the right direction.
I would advise you not to go down this road though. In order to get access to the filesystem, the users are required to set their browser's security settings extremely low. This is clearly not a good idea. That's why it's a default setting to have access to this stuff. It's also why you can't do much with file input boxes using javascript. It poses a huge security risk and I repeat I advise you not head down this road. Perhaps if you explained your reasons for wanting to do this we could offer some alternative solutions/ideas.
var filePath = 'c:\\test.txt';
if (navigator.userAgent.indexOf('MSIE') == -1 && Components)
{
try
{
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(filePath);
if (file.exists())
{
alert('Found!');
}
else
{
alert('Not found!');
}
}
catch(e)
{
alert(e);
}
}
else
{
try
{
var objA = new ActiveXObject('Scripting.FileSystemObject');
if(objA.FileExists(filePath))
{
alert('Found!');
}
else
{
alert('Not found!');
}
}
catch(e)
{
alert(e.message);
}
}
The IE stuff will work definately work, but I haven't tested the mozilla code (only have IE installed atm), so not too sure if that will work straight away or not, at the least it should point you in the right direction.
HTH
|
|
|
|