Jump to content

external javascript problems


Recommended Posts

I am new to javascript. I've created a basic form with HTML as

**************************************

<script type="text/javascript" src="...." >

<form>

username:

password:

address:

..........

</form>

*********************************

I have created an external javascript. Now how to write code for form validation from this external javascirpt??

I've searched in many books and forums but they all provide solutions with internal js. How to write external js for form validation?

Suppose for the same form I've used CSS also like:

************************************

<div id="user_reg">

<form>

username:

password:

address:

..........

</form>

</div>

************************************

How to write external js for form validation??

Link to comment
Share on other sites

I am new to javascript. I've created a basic form with HTML as...

Very good; the easiest way to learn anything new is to have an actual task you want to implement.

I have also recently started using JavaScript, and this topic shows quite a few sample JS that I have partly developed, partly picked up on the web and modified for my needs.

Basically, JS can get elements from the HTML by either addressing them by name (when name="..." was used in the HTML tag) or by id (when id="..." was used in the HTML tag).

You do that using either

elem = document.getElementsByName('...');

or

elem = document.getElementById('...');

You can then address that elements properties (elem.value, elem.length, etc.). You can also, if you have modified anything, send it back to its original location:

document.getElementsByName('...') = elem;

or

document.getElementById('...') = elem;

Of course you can also change certain properties directly

document.getElementById('...').value = 'new value';

Google is a great help finding JS samples, or answers to specific questions you have.

One of the sites that helped me a lot (HTML, CSS, JS) during the project I mentioned earlier is http://www.w3schools.com/

Of course you can come back here and ask anytime you cannot find the answer / solution to a question.

Link to comment
Share on other sites

I am new to javascript. I've created a basic form with HTML as

**************************************

<script type="text/javascript" src="...." >

<form>

username:

password:

address:

..........

</form>

*********************************

When showing code in a forum, it is best to use the code tags around the code (using the <> button in the forum editor. code results in easy readable monospace font, and also different code elements are differently colored. E.g.

<script type="text/javascript" src="...." >
<form>
username:
password:
address:
..........
</form>

Link to comment
Share on other sites

I have created an external javascript.

From my experience it is easiest to keep the scripts in the HTML document during the development phase. Once everything works, you can then remove it from the doc and place it as an external script.

What browser are you using? I used Firefox for my project, and I found that the Firebug add-on is a great JS debugger. It detects and shows you errors in the script, and it shows you all the properties and values of any elements used in your document.

Firebug: http://getfirebug.com/

Link to comment
Share on other sites

  • 6 months later...

What browser are you using? I used Firefox for my project, and I found that the Firebug add-on is a great JS debugger. It detects and shows you errors in the script, and it shows you all the properties and values of any elements used in your document.

This is more like a note to myself...

I have until recently done all JavaScript debugging on Firefox. However, when I found that a certain script did not work on Internet Explorer, I had to go and find a way to debug under IE. It took me quite a while to find out that F12 invokes IE's own debugger, and it is pretty powerful.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy