Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Refreshing form value Function
Old 04-23-2005, 04:36 PM Refreshing form value Function
Logical Program's Avatar
Super Talker

Posts: 130
Location: Atlanta, Georgia
Trades: 0
I've got a form, and I have a function that [is supposed to] takes the value of part of the form, and sets it as the hidden value called "user". If the user value is blank, for form will return false, and give an alert. For some reason, my function won't do anything, and I think it's because I use a variable in my document call... Here's my codes...

The Function...
HTML Code:
<script language="JavaScript">
function refresh_user(formname, fieldname){
	var user = document.formname.fieldname.value
	document.formname.user.value = user
	if (user.length < 1){
		alert("Provide A User Value In The Form!")
		return false;
	} else {
		return true;
	}
}
</script>
And the form syntax...
HTML Code:
<form onSubmit="return refresh_user(addadmin, id);" name="addadmin" action="'.$currentquery.'&sub3=add" method=post>
<input type=hidden name=user value="">
<table><td width=100>User ID:</td><td><input type=text name=id size=3></td></table>
Those are the parts that're needed to help out... Thanks, in advance.
__________________

Please login or register to view this content. Registration is FREE
- For all of your website programming and design needs, make the logical choice. Logical Assistance For Real-World Clients.
Logical Program is offline
Reply With Quote
View Public Profile Visit Logical Program's homepage!
 
 
Register now for full access!
Old 04-23-2005, 05:28 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
Try this instead
HTML Code:
<script type="text/javascript">
function refresh_user(formname, fieldname)
{
	var user = document.forms[formname][fieldname].value;
	document.forms[formname].user.value = user;

	if (user.length < 1)
    {
		alert("Provide A User Value In The Form!");
		return false;
	}
    else
		return true;
}
</script>
formname and fieldname were being treated as strings, so you can't use them the way you were using them. Since you can use document.forms as an array containing all the forms on the page, you can use the string formname as the index. And you can also use document.<formobj> as an array for every element within the form, so you can use fieldname as an index.
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 04-23-2005, 06:09 PM
Logical Program's Avatar
Super Talker

Posts: 130
Location: Atlanta, Georgia
Trades: 0
:-/ Still does the same thing... I have no clue what's wrong.
__________________

Please login or register to view this content. Registration is FREE
- For all of your website programming and design needs, make the logical choice. Logical Assistance For Real-World Clients.
Logical Program is offline
Reply With Quote
View Public Profile Visit Logical Program's homepage!
 
Old 04-23-2005, 09:38 PM
Logical Program's Avatar
Super Talker

Posts: 130
Location: Atlanta, Georgia
Trades: 0
Problem Fixed!

The Function... (The one Chroder altered for me, Thanks)
HTML Code:
<script language="JavaScript">
function refresh_user(formname, fieldname)
{
	var user = document.forms[formname][fieldname].value;
	document.forms[formname].user.value = user;

	if (user.length < 1){
		alert("Provide A User Value In The Form!");
		return false;
	} else {
		return true;
	}
}
</script>

And the form... (Single-Quoted Arguments)
HTML Code:
<form onSubmit="return refresh_user(\'addadmin\', \'id\');" name="addadmin" action="'.$currentquery.'&sub3=add" method=post>
<input type=hidden name=user value="">
<table><td width=100>User ID:</td><td><input type=text name=id size=3></td></table>
__________________

Please login or register to view this content. Registration is FREE
- For all of your website programming and design needs, make the logical choice. Logical Assistance For Real-World Clients.
Logical Program is offline
Reply With Quote
View Public Profile Visit Logical Program's homepage!
 
Reply     « Reply to Refreshing form value Function
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13515 seconds with 12 queries