disable text field..not with "disabled" tag btw

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

disable text field..not with "disabled" tag btw

Post by qads »

elo
got a weird problem, i have 2 text fields that i don't want the user to use, i tried useing:

Code: Select all

<input name="coupon_valid_from" type="text" size="10" disabled>
if i use this method, then its not set in php, so i can't see what was in it (i use another script to put value in it).

is there anything else i can use for this? something that will stop the user from typeing in this field, but it should be set in php...

thanks alot
User avatar
Leviathan
Forum Commoner
Posts: 36
Joined: Tue Sep 23, 2003 7:00 pm
Location: Waterloo, ON (Currently in Vancouver, BC)

Post by Leviathan »

So basically you want hidden fields so you can pass a value to the server without the user knowing? I can't remember the exact syntax, but you either use

Code: Select all

<input type="hidden"...> or <input type="text" hidden...>
. I think it's the first choice.
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

well, not exectly, i still need to show what is in the text box, i am playing around with hidden fields now, hopefully i will get it working...if so, i will post it...

any idea on how to call a function 2 times "onclick"?

Code: Select all

<a href="#" onClick="getCalendarFor(document.coupon.coupon_valid_from);getCalendarFor(document.coupon.coupon_valid_from_show);return false;">Choose Date</a>
this is not working :?

thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

<html><body>
	<form method="post" action=".">
		<input type="text" name="test1" value="value 1" readonly="readonly" />
		<textarea name="test2" readonly="readonly" >value 2.a
		value 2.b</textarea>
	</form>
</body></html>
see also: http://www.w3.org/TR/html4/interact/forms.html#adef-readonly
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

For normal INPUT fields you can use the JavaScript blur() function, if that helps.

Code: Select all

<input type="text" size="40" onClick="blur();">
This will disallow the user to edit any text in the input box.
User avatar
Leviathan
Forum Commoner
Posts: 36
Joined: Tue Sep 23, 2003 7:00 pm
Location: Waterloo, ON (Currently in Vancouver, BC)

Post by Leviathan »

To call a function twice, you could make a second function that does the two calls for you, and call that new function.

Code: Select all

a &#123;
    b(1);
    b(2);
&#125;


<input type="text" name="somefield" onclick="a();">
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

cool, readonly works nicely :D


thanks guys :)
User avatar
Vincent Puglia
Forum Commoner
Posts: 67
Joined: Thu Sep 04, 2003 4:20 pm
Location: where the World once stood

Post by Vincent Puglia »

Hi

<input type="text" size="40" onFocus="this.blur();alert('Read Only')">

The alert isn't necessary, but it does give the user an idea of what is going on.

Re the 2fer:

send X number of arguments:

<a href="#" onClick="getCalendarFor(document.coupon.coupon_valid_from, document.coupon.coupon_valid_from_show);return false;">Choose Date</a>

and in the function, loop:

getCalendarFor()
{
var loopCnt = arguments.length;
for (var i = 0 ; i < loopCnt; i++)
{
someVar = arguments; // the nth argument being passed
....the function's code...
}

Vinny
Post Reply