If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Urgent ! How to Enable a text field only on selecting a radio button in JSP

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Jul 2002
Posts: 11
Urgent ! How to Enable a text field only on selecting a radio button in JSP

Hello -
I want to create a radio button and next to it are two text fields. Only on select that radio button, the two text fields should get enabled. How to do this? Thanks. Edwk
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: Jan 2003
Location: de/ro
Posts: 12
perhaps this can help

This is a JavaScript and I don't understand why do you want to code it in JSP!

The function enableText is triggered at onClick on the radio button.
it checks if exists any enabled text fields and disable them and then enables the required fields, specified by the elementId.

Here it is:

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<script language="JavaScript">
<!--
var currentFields = "";

function enableText(elementId){
if (currentFields != "") {
eval("document.forms[0].text_" + currentFields + "_a.disabled=true;");
eval("document.forms[0].text_" + currentFields + "_b.disabled=true;");
}
eval("status = document.forms[0].text_" + elementId + "_a.disabled");
if (String(status) == String("true")) {
eval("document.forms[0].text_" + elementId + "_a.disabled=false;");
eval("document.forms[0].text_" + elementId + "_b.disabled=false;");
}
currentFields = elementId;
}
//-->
</script>
</head>

<body bgcolor="#FFFFFF">
<form name="oneForm" method="post" action="">
<input type="radio" name="radioButton" onclick="javascript:enableText('1');"><input type="text" name="text_1_a" disabled><input type="text" name="text_1_b" disabled>
<br>
<input type="radio" name="radioButton" onclick="javascript:enableText('2');"><input type="text" name="text_2_a" disabled><input type="text" name="text_2_b" disabled>
</form>
</body>
</html>

Last edited by wakhy; 01-03-03 at 04:40.
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Jan 2003
Location: KC, MO
Posts: 7
definelty go w/ the javascript ... but doesnt work w/ Netscape so be aware.
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Jan 2003
Location: de/ro
Posts: 12
Exclamation it works with mozilla&co.

There was a mistake when I submitted the script, the "javascript" statement from the onclick event was transformed in "java script" by the forum parser.
So if you change the "java script:" fron the onclick event handler from the <input type="radio" then it will work on mozilla & co.

sorry ... but the forum parser is kind of strange! .....

I tried to resubmit the code in the proper way, but there is no chance that I could bypass the parser.... so please do the above changes in the code manually.


Last edited by wakhy; 01-06-03 at 16:54.
Reply With Quote
  #5 (permalink)  
Old
Registered User
 
Join Date: Jan 2003
Location: KC, MO
Posts: 7
i didnt think that

document.form1.field.disabled = true worked in NS 4.7

my bad i guess i was thinking wrong
Reply With Quote
  #6 (permalink)  
Old
Registered User
 
Join Date: Jan 2003
Location: KC, MO
Posts: 7
Yeah I just tried it out it will work in NS 7 but not NS 4.7 so it's your call on if you want to do it that way. A nice little trick to disabling form elements in NS 4.7 is just putting:

onFocus="blur();"

in the form elements tag. That way as soon as a user clicks on it, they will be kicked from the focus.
Reply With Quote
  #7 (permalink)  
Old
Registered User
 
Join Date: Jan 2003
Location: de/ro
Posts: 12
Quote:
Originally posted by ghw0668
Yeah I just tried it out it will work in NS 7 but not NS 4.7 so it's your call on if you want to do it that way. A nice little trick to disabling form elements in NS 4.7 is just putting:

onFocus="blur();"

in the form elements tag. That way as soon as a user clicks on it, they will be kicked from the focus.

yes, but is kind of annoying ... for a user... bad usability ....
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
Pingbacks are On
Refbacks are On