Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-07-2008, 01:02 AM   PM User | #1
Trubo
New to the CF scene

 
Join Date: Oct 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Trubo is an unknown quantity at this point
Working with forms

I am working with javascript forms for an assignment. The goal is to be able to prompt for a input, check it, and then write it to the page or display it in a new pop-up window. So far I have the javascript correctly checking my data, but I can't figure out how to make it echo the results back.

In the script I have a few testing functions to make sure the input is the correct form. They look something like...
function isEmpty(elem) { } --checks to see if field empty
function isValid(elem) {} --checks to see if field correct
function validate(form){} --returns true if (isEmpty && isValid)

In the body i have some code, listed below, that handles my input.
<input type="text" size="30" name="name1" id="name1" onchange="if (isEmpty(this)) {isValid(this)}" /><br />
<input type="submit" />

I'm mostly just looking for a little guidance on how to declare an output function and where/how to call it.

The simple examples I have looked up all seem to deal with input that isn't verified, and I can't quite figure out how to make that example work with what I am doing.
Trubo is offline   Reply With Quote
Old 10-07-2008, 04:30 AM   PM User | #2
rangana
Senior Coder

 
rangana's Avatar
 
Join Date: Feb 2008
Location: Cebu City, Philippines
Posts: 1,752
Thanks: 65
Thanked 372 Times in 365 Posts
rangana will become famous soon enoughrangana will become famous soon enough
What do you mean by output function? I guess you mean an alert()

Anyway, please elaborate a little further, and show us the code and the markup so we could easily understand what your desire is.
__________________
Learn how to javascript at 02geek

The more you learn, the more you'll realize there's much more to learn
Ray.ph
rangana is offline   Reply With Quote
Old 10-07-2008, 05:01 AM   PM User | #3
Trubo
New to the CF scene

 
Join Date: Oct 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Trubo is an unknown quantity at this point
I have reworked a fair amount of my code since making my first post.. so I'll try and make a more complete example of what my code looks like. I was trying to follow some form examples that I had found, and I think I was making some things more complicated then needed. Here is some more streamlined code.

<head>
foo

<script type="text/javascript">
<!--

function isValid(elem) {
var str= elem.value;
var re = </foo$/>
if (!str.match(re))
{
alert("abc");
setTimeout("focuselement('" + elem.form.anem + "', '" + elem.name +"')",0;
return false;
}
else
{
return true;
}
}

function printData(?????) {
document.write("The entry was: ");
document.write(?????);
}

-->
</script>
</head>

in the body I declare the following:

Enter an amount:
<input type="text" size="30" name="name1" id="name1" onchange="isValid(this)" /><br />
<input type="submit" onclick="printData()" />

This code is making sure my regular expression is in a correct form. It prints "The entry was: " so I know my function printData is doing at least something. However, it seems to me like I need to pass the validated regular expression to the printData(?????) function, that or I am typing the wrong thing in the document.write(?????) line.
Trubo is offline   Reply With Quote
Old 10-07-2008, 06:15 AM   PM User | #4
rangana
Senior Coder

 
rangana's Avatar
 
Join Date: Feb 2008
Location: Cebu City, Philippines
Posts: 1,752
Thanks: 65
Thanked 372 Times in 365 Posts
rangana will become famous soon enoughrangana will become famous soon enough
What are you trying to do? I'm confused.

Also, don't use document.write, use nodeValue to add new value on your node instead.
__________________
Learn how to javascript at 02geek

The more you learn, the more you'll realize there's much more to learn
Ray.ph
rangana is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:06 PM.


Advertisement
Log in to turn off these ads.