Jump to content

how to add a text field to radio button


jcc5018

Recommended Posts

Hey, I am trying to make a feedback form for my portfolio. I want to design it so that there is a section for general contact information then a section for if the person is a business representative responding to my resume. So how would i make a radio button selector that would ask something like Are you a business representative? *Yes * No and then if they click yes, another section would become available that has them fill out more information about the company they are with. And if no, nothing else will show up. I am doing this in Dreamweaver, if i need to learn another code to achieve this, can you give me an example of that code, or a tutorial or something that could help me out. Also, I want to have a radio button set to ask where they learned about my site with two of the options being: Verbal Reference and Other. I also want them to type in Who or what in a box next to the option if that option is selected. How do i connect a text box to that option?Thanks for any help you can provide.

Link to comment
Share on other sites

Guest FirefoxRocks

From the top of my head:JavaScript - put that in the <head> section of your page. I don't remember how

<script type="text/javascript">function showBusinessRep() {   if(document.getElementById('yes_business_rep').checked == true) {	   document.getElementById('business_rep_details').style.display = block;   }   else if (document.getElementById('no_business_rep').checked == true) {	  document.getElementById('business_rep_details').style.display = none;   }}</script>

The HTML page (please note that you need to work in Code View in Dreamweaver):

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>Feedback Form</title>(... the above script placed here ...)</head><body>(... some other code ...)<form action="whereDoesTheDataGo.php" method="post"><fieldset><legend>Section Name (replace this with an appropriate name)</legend>(... some other form stuff if necessary...)Are you a business representative? <br><input type="radio" name="business_rep" id="yes_business_rep" value="yes" onclick="showBusinessRep();"> Yes<input type="radio" name="business_rep" id="no_business_rep" value="no" onclick="showBusinessRep();"> No<div id="business_rep_details" style="display: none">(...put the stuff to show up in here ...)</div></form>(... some other code...)</body></html>

It should work like that. If anyone sees anything wrong with my code, don't hesitate to correct it! :)

Link to comment
Share on other sites

I'm going to be nice and give you the form layout and you can do all the posting and stuff...sec lemme get my boook..post this in your div : (not here for this example I am going to use a table for the convenience. By all mean change my example. Note: I would not recommend mailing to your email and leaving your email open unless its a small traffic website. It could produce spam. It would be best to to include a CGI script on your server and store the email in your database)

<form method="post" enctype="text/plain" action="mailto:yourmail"><table><tr><colgroup align="right" valign="top"><td>Are you a business representative?<p><input type="radio" name="category" value="Yes" />Yes<br /><input type="radio" name="category value="No" checked="checked" />No<br /></tr></td></table><br /><table><tr><td><p>Where did you hear of this site? <select name="where" size="1"><option>Verbal Reference</option><option>Other</other></select></p>

Note in my code there is no if the person hits the other option or if they check it does a new form and stuff. the reason behind it is I do not know what code that would require. Sorry. Anyone reading this who does know feel free to edit my code to include it! Or you can tell me what to look for an I would gladly finish the code

Link to comment
Share on other sites

It's a terrible idea to use mailto in anything, it relies on the user having a mail client installed and configured in order to work and, like you said, it's going to receive a lot of spam (regardless of how much traffic you have). The correct way is to submit the form to something like a PHP script that can send the mail, it's really easy to send mail using PHP. If the form contains a lot of information it might be more useful to just store the entire results in a database and send yourself a mail to let you know there was a new submission. In that case you would also need to build a page that you can login to and get a list of the submissions to look at.

the reason behind it is I do not know what code that would require.
But according to your profile you are "adept" at Javascript and PHP, and this type of thing is pretty basic, even for someone who is only proficient. Since adept is better then proficient surely you should be able to do that.
Link to comment
Share on other sites

Maybe you should replace it with novice. For reference, I consider myself adept and I've been programming professionally for 6 years after getting a degree in computer science.

adept: One fully skilled or well versed in anything; a proficient; as, adepts in philosophy; Well skilled; completely versed; thoroughly proficient
http://en.wiktionary.org/wiki/adept
Link to comment
Share on other sites

im only a senior in high school. so what if i dont know the definitions of terms? your adept is professional. your novice is my learning how to make divs different colors. seems we vary on that aspecct

Link to comment
Share on other sites

Yeah, I'm using a scale like this:novice/beginnerproficient/competentadept/intermediateexpertmasterIf you think that you can check out a couple tutorials and copy and some code and jump up a few levels, then yeah, I disagree with you. I think it requires practical real-world experience and serious study to move on that scale.

Link to comment
Share on other sites

It's a terrible idea to use mailto in anything, it relies on the user having a mail client installed and configured in order to work and, like you said, it's going to receive a lot of spam (regardless of how much traffic you have). The correct way is to submit the form to something like a PHP script that can send the mail, it's really easy to send mail using PHP. If the form contains a lot of information it might be more useful to just store the entire results in a database and send yourself a mail to let you know there was a new submission. In that case you would also need to build a page that you can login to and get a list of the submissions to look at.But according to your profile you are "adept" at Javascript and PHP, and this type of thing is pretty basic, even for someone who is only proficient. Since adept is better then proficient surely you should be able to do that.
um, thanks for the responses so far, to be honest, i probably wont check them out for a little while because i am attempting to finish the main part of my online portfolio. The form questions are a means of me getting feedback, hopefully from employers responding to my resume. I am coneected to a Penn State server for now which has the formmail.cgi script to send the mail to me. Would that work? I finally figured out how to connect to that, but like i said, I'll probably be figureing out the rest of the feedback form, only after i finish trying to update my site into a flash portfolio I'm trying to create. (So Im trying to understand action script and XML at the same time) I actually found a pretty detailed tutorial on how to make a better picture viewer than what I have set up already, and that would hopefully save me a lot of time in making the rest of it, but I'm going have to study it some and see if i can make some conversions to make it work better for my needs. You can check out what i managed to accomplish so far here : http://www.personal.psu.edu/jcc5018/House3.htmI will try to upload the code i have so far for my form when i get a chance so you guys can check it out for me. Thanks again for the help.
Link to comment
Share on other sites

The formmail.cgi script will work for sending the mail, but unfortunately it doesn't protect against spam because you have to put the email addresses in hidden form tags that a bot could read. If you want to get around that then I guess you could have some Javascript that would add the form elements dynamically where you could break up the email address, but that's only necessary if you're worried about the addresses getting picked up by spam bots.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...