473,668 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Making Form Fields Appear or Disappear,Based on the Value of other Fields

63 New Member
Here is the other one..This requires a textbox to open while clicking of a radiobutton in one part and in the other part on the click of a list/menu.

I want that..as I click the second radiobutton,the textbox be displayed so that the data may be posted.else itremains hidden or engraved..and a similar other problem with list/menu in place of rado button.

Tablename:form
Columnames :(i) des,des_url
Columnnames:(ii )dom,domname

[PHP]<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" >
<table width="90%" align=center cellpadding=2 class=medium>
<tbody>
<tr bgcolor=#42519c >
<td colspan=2><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong> 1. Type of Web Site </strong></font></td>
</tr>
<tr>
<td width="42%"><fo nt color="#333333" size="1" face="Verdana, Arial, Helvetica, sans-serif"><br>
<input type=radio name=design value=New_Web_S ite />
New Web site design </font></td>
<td width="58%" rowspan=2><font color="#333333" size="1"
face="Verdana, Arial, Helvetica, sans-serif"><br>
</font> </td>
</tr>
<tr>
<td><font color="#333333" size="1" face="Verdana, Arial, Helvetica, sans-serif"><br>
<input type=radio name="design" value=Re-design />
Re-design a Web site</font></td>
</tr>
<tr>
<td width="42%"><fo nt color="#333333" size="1"
face="Verdana, Arial, Helvetica, sans-serif"><br>
If re-design, what is the URL?&nbsp; </font></td>
<td valign=bottom>< div align=right><fo nt color="#333333" size="1"
face="Verdana, Arial, Helvetica, sans-serif"><br>
<input maxlength=80 size=50 name=des_url >
</font></div></td>
</tr><tr>
<td class=ws_body valign=top colspan=2><font color="#333333" size="1"
face="Verdana, Arial, Helvetica, sans-serif">Do you have a Internet Merchant Account?</font></td>
<td class=ws_body valign=top><fon t color="#333333" size="1"
face="Verdana, Arial, Helvetica, sans-serif">
<select name=ima>
<option selected>Select </option>
<option value=yes>Yes</option>
<option value=no>No</option>
<option value="not sure">Not Sure</option>
</select>
</font></td>
</tr>
<tr>
<td class=ws_body valign=top width="18%"><fo nt color="#333333" size="1"
face="Verdana, Arial, Helvetica, sans-serif">If yes, with what company <br>
(WorldPay, PaySystems, etc)?</font></td>
<td class=ws_body valign=center colspan=2><div align=right><fo nt color="#333333" size="1"
face="Verdana, Arial, Helvetica, sans-serif">
<input maxlength=500 size=50 name=imabank>
</font></div></td></tr>
</tbody>
</table>
</form>[/PHP]
Jan 9 '08 #1
11 3556
nathj
938 Recognized Expert Contributor
Hi,

What I've deon to overcome this issue is that when the form is built up I have check boxes to the left of textboxes or slect boxes or whatever. The controls to the right start off in a span with a display state of none. A sample section of a form would look lie this:
[html]
<div class="row">
<span class="label">
<label for="useSession ">Session: </label>
<input id="useSession " class="check" type="checkbox" onclick="this.v alue=this.check ed; toggleDisplaySt ate('sessionLis t')" title="search on session" value="true" name="useSessio n"/>
</span>
<span id="sessionList " class="formw" name="sessionLi st" style="display: none;">
<select id="session" name="session">
<option value="1">Sessi on 1</option>
<option value="2">Sessi on 2</option>
</select>
</span>
</div>
[/html]
The onclick event of the check box could be used as the onchange evet of a text box. It calls a simple javascript function that looks like:
Expand|Select|Wrap|Line Numbers
  1. function toggleDisplayState(poObjectToDisplay)
  2. {                                                         
  3.  
  4.     var loObject = document.getElementById(poObjectToDisplay);
  5.  
  6.     //test the current state of the object and toggle opposite state.
  7.     if (loObject.style.display != '' && loObject.style.display != 'none') 
  8.     {
  9.         loObject.style.display = 'none';
  10.     }
  11.     else 
  12.     {
  13.         loObject.style.display = 'inline';
  14.     } 
  15. }
  16.  
This is a very simplistic solution but then when I check the post data I check the stae of the check box to see if I need to check the contents of the other control.

A more complex solution would be to have the onclick event call a javascript function that use the XMLHTTPRequets object to get the information that was required and then write the control only when it is needed. When it is not need simply write nothing back in place of the control definition. This process is essentially AJAX and may be overkill for your project. If you want to investigate the AJAX route I would be happy to help you out and even post some psuedo code.

Cheers
nathj
Jan 9 '08 #2
TechnoAtif
63 New Member
Hi Nathj..thanx for the reply..The solution you have provided.is indeed simple.
But you have used the checkbox..can the same be replicated for radibutton or list box. IF yes please cite an example.it would be easier for me.

The other point is that you have made use of session.But i dont want to use session values.so is there any way to perform the task without using the session.

The last one . Isn't there any way to do this task in PHP alone, without .using javascript or as you mentioned.Ajax. . Is it more difficult to do it in PHP alone ?

Regards
TechnoAtif
Jan 9 '08 #3
nathj
938 Recognized Expert Contributor
Hi Nathj..thanx for the reply..The solution you have provided.is indeed simple.
But you have used the checkbox..can the same be replicated for radibutton or list box. IF yes please cite an example.it would be easier for me.

The other point is that you have made use of session.But i dont want to use session values.so is there any way to perform the task without using the session.

Regards
TechnoAtif
Hi TechnoAtif, Often simplicity is best, but thats always a judgement call.

If you wish to use this for a radio button then you may have to play around with it a bit. The radio button control ahas an onclick event so you could use it in the same way. However, I'm not sure how this would handle deactivating controls, you may have to add some extra code for that.

As for text based controls you could simply use the onchange event to handle this. However, you may then want to perform more tests on the contents of the text field - simply pass the value of the text field and if it's empty disable the display and if its not empty enable the display.

If you have aplay around with te code smaple from before but alter it to use a radio button then I may be able to help you tweak it when the time comes.

Cheers
nathj
Jan 9 '08 #4
TechnoAtif
63 New Member
Can you please sort out my other problems too that i posted today.Please have a look on those posts if you can.

Regards
Atif
Jan 9 '08 #5
TechnoAtif
63 New Member
Hi Nathj..

Its great that i now know how to solve this problem in case of checkboxes and thanx to you for that. but still since in the form radiobutton has been used to display the textboxes.so i have to do it in any case..Believe me these problems have choked up my mind since the last one week or so.Desperate to get the solution,this was my ultimate option to sought help from you noble people.You should have seen my other posts also that i posted today. So please help me out.

Regards
TechnoAtif
Jan 9 '08 #6
nathj
938 Recognized Expert Contributor
Hi Nathj..

Its great that i now know how to solve this problem in case of checkboxes and thanx to you for that. but still since in the form radiobutton has been used to display the textboxes.so i have to do it in any case..Believe me these problems have choked up my mind since the last one week or so.Desperate to get the solution,this was my ultimate option to sought help from you noble people.You should have seen my other posts also that i posted today. So please help me out.

Regards
TechnoAtif
Hi TechnoAtif,

Having read through your code more thoroughly I have one question. Am I correct in thinking that the visitor to the site can choose either 'New Site Design' or Re-design'?

If so then you could try the following for each radio button:
[html]
onclick = toggleDisplaySt ate('newsite', 'redesignsite')
[html]
The two ID/names given in this call would need to be the ID/name of the textbox against each radio button. The JS woudl then be slightly different:
Expand|Select|Wrap|Line Numbers
  1. function toggleDisplayState(poObjectToDisplay, pcObjectToHide)
  2.  
  3. {                                          
  4.     var loObjectToShow = document.getElementById(poObjectToDisplay);
  5.     var loObjectToHide = document.getElementById(pcObjectToHide);
  6.  
  7.     //test the current state of the object and toggle opposite state.
  8.  
  9.     loObjectToShow.style.display = 'inline';
  10.  
  11.     loObjectToHide.style.display = 'none';
  12.  
  13.  }
  14.  
Becuase you can't uncheck a radio button it only changes when another button in the same group is checked this even simpler code should do the trick for you.

Remeber that you will need to have the text boxes defined but with a style="display: none". If there is more than one control to be shown when a radio button is clicked simply put them all in a <div> and pass the id of the div to the JavaScript.

Finally this call will need to be made on all the radio buttons and at present only allows you to enable and disable one set of controls. If you need it to enable or disable more in one go then let me know and we can look at using list of controls as parameters.

Cheers
nathj
Jan 10 '08 #7
TechnoAtif
63 New Member
Hi Nathj

Thanx for your coooperation throughout.Your advice has further improved my knowledge bank.For this problem i have implented your ideas ,they were good.In addition to that I have tried another thing from some book and i got exactly what i wanted.Here is the code that could help others like me.It involves the combination of javascript and a little bit of CSS

[HTML]<style type="text/css"> //use of css
.hidden
{
position: absolute;
left: -1500em;
}
</style>
<script type="text/javascript">
addLoadListener (init);
function init()
{
var optional = document.getEle mentById("optio nal");
optional.classN ame = "hidden"; //calling the CSS class
var Re_design = document.getEle mentById("Re_de sign");
Re_design.oncli ck = showOptional;
var New_Web_Site = document.getEle mentById("New_W eb_Site");
New_Web_Site.on click = hideOptional;
return true;
}function showOptional()
{
var optional = document.getEle mentById("optio nal");
optional.classN ame = "";
return true;
}

function hideOptional()
{
var optional = document.getEle mentById("optio nal");
optional.classN ame = "hidden";
return true;
}
</script>
<body onLoad="init()" >[/HTML][HTML]
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" >

<fieldset>

<input type=radio name=design id=New_Web_Site />

<!--<input type="radio" name="read" id="readYes" />-->
<label for="New_Web_Si te">
New Web site design
</label>
<input type=radio name="design" id=Re_design />

<!--<input type="radio" name="read" id="readNo" />-->
<label for="Re_design" >
Re-design a Web site
</label>
<div id="optional">
<label for="des_url">
If re-design, what is the URL?&nbsp;
</label>
<input type="text" maxlength=80 size=50 id = des_url name=des_url >
</div>
</fieldset>
</form>[/HTML]

Follow this up by your insert query in PHP.and you will have the solution.

Regards
TechnoAtif
Jan 10 '08 #8
nathj
938 Recognized Expert Contributor
Hi TechnoAtif,

I'm glad you have got a solution to your probblem and I am also glad that you have gained some more knowledge through the process - I always think that makes the struggle worth while.

I'm happy to have helped.

cheers
nathj
Jan 10 '08 #9
TechnoAtif
63 New Member
Yes Nathj..
Hats off to the noble peace of work you people are doing to enrich novices like us with proper knowledge.

Do You have answers to 2 of my other posts. If yes then kindlyhelp..oth erwise plz suggest some other place from where i could get help on them.


Regards
TechnoAtif
Jan 10 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2935
by: middletree | last post by:
For an ASp Intranet app, I have some code that should work, but I am not able to make it happen for some reason, after spending considerable time on this. I am pretty thick when it comes to javascript; I just don't get the syntax at all. If anyone could help, I would appreciate it. I'm probably pretty close. Please note that because it's an Intranet, all users have to use IE 5 or higher. Situation: 3 form fields on an ASP. <select>...
1
3439
by: Hal Vaughan | last post by:
I have a case where the user can select several choices from my 1st <SELECT> element. The user's choice on the 1st <SELECT> effects what the possible choices are for the 2nd element. Currently the 2nd element is a <TEXT> input, but I'd like to be able to make it a <TEXT> element when certain items are selected from the 1st <SELECT> and a <SELECT> when other choices are selected. Is there a way to either change an element from <TEXT> to...
17
1550
by: KS | last post by:
I got 2 inputs in a form where I want check if start > end. Seems like it just compare the first number when I got this code in javascript "if(document.all.start > document.all.end)" How do i solve this so it compare 2 > 10 as, is two bigger than ten, and not, is two bigger than one. Thanx in advance
7
3598
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title> </head> <style type="text/css">
5
3740
by: Sami | last post by:
Please bear with me, and if you answer this question, please do it step by step. I am new at Access, not at all sophisticated. I am using Office XP. This will need to be read in Access for Office 2000. I am creating a database to track student athletes. I have created the following tables. The table title is to the far left, with fields under each. The common field will be the StudentID field, which is their student number assigned...
4
7003
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the user enters the last qualifying field on the main form. In one case this works fine, the subform shows the data the user wants to update -- which means showing all the data put in previously (ie showing this via the requery and the continuous...
9
2306
by: Tony Williams | last post by:
I have two tables 1.tblmonth which holds two fields txtmonth and txtqtrlabel and 2. tblmain which holds a number of fields but in particular a field called txtqtrlabel2. The two tables are linked on txtqtrlabel and txtqtrlabel2. I have a main form based on tblmonth which has a subform based on tblmain, the two forms are also linked on the same fields. The data entered into txtmonth could be "30/09/04" and the txtqtrlabel data would be...
4
3169
by: Kathy | last post by:
What is the standard technique for handling the fields in the following scenario on a continuous form? Multiple Divisions. Each Division has multiple Buildings. Each Building has a Supervisor. Tables: (abbreviated) TblDivision DivisionID
2
1940
by: Cerebral Believer | last post by:
Hi folks, Can anyone help me with this form: http://futurebydesign-music.com/_member/club_fbd_reg.php I have followed to coding instructions aas closely as I can, but I am getting errors about not filling in all the fields on the form correctly when I test it. Is validating a form with radio buttons difficult?
0
8890
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8791
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8575
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8653
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5677
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2784
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2018
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.