Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing a form value to a function and getting its length

Status
Not open for further replies.

shnazz

Technical User
Jul 27, 2004
22
US
Hi. I have a form that has an onSubmit statement calling a javascript function with an arguement that is supposed to pass a form value. It looks something like this:

<script language="JavaScript">
function digit_check(input_string) {
if ( input_string.length==10 ) {
...
...
</script>

<form method="post" name="edit" action=.... onsubmit="javascript:return digit_check(phone_number)>
Phone Number : <input type="text" name="phone_number" value=<?php echo "$row[phone_number]" ?> />
...
...

If I output "input_string.value" from the function then I get the proper string. If I try to get its length "input_string.length" then I get an "undefined" message when I output the value. I have tried using the DOM to get the form value ie. document.form.phone_number... but that does not help. I know I am missing something really silly, somebody please help!

 
You're passing the actual object to the function, not the value within the object.

Change this:
onsubmit="javascript:return digit_check(phone_number)"

to this:
onsubmit="return digit_check(document.edit.phone_number.value)"

*cLFlaVA
----------------------------
A polar bear walks into a bar and says, "Can I have a ... beer?"
The bartender asks, "What's with the big pause?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top