scale Posted November 12, 2006 Share Posted November 12, 2006 Hi all,i have 3 radio buttons, which is a, b and c, and 1 submit button. i want to do a function, for example, if i click on a and b button, it show nothing. but if i click on c button, it appear a textarea, which ask me to key in some words. how to do the onclick function? and how to alert user if not key in any words inside textarea?Thanks. Link to comment Share on other sites More sharing options...
MrAdam Posted November 12, 2006 Share Posted November 12, 2006 i don't really understand that..could you try to explain it better? Link to comment Share on other sites More sharing options...
Webworldx Posted November 12, 2006 Share Posted November 12, 2006 You've asked for two interesting ideas - but we don't just write the full code for you here sorry.Show us how far you've got with the coding, and we will point you in the right direction Link to comment Share on other sites More sharing options...
Jonas Posted November 12, 2006 Share Posted November 12, 2006 Hi all,i have 3 radio buttons, which is a, b and c, and 1 submit button. i want to do a function, for example, if i click on a and b button, it show nothing. but if i click on c button, it appear a textarea, which ask me to key in some words. how to do the onclick function? and how to alert user if not key in any words inside textarea?Thanks.So you want something like this:Alternative A Alternative B Other (specify) And when clicking the radio-button for Other, you get a text-area? Hmm, I think if you want the submit button to catch the input from the text-area, that it has to be there in the code in advance, so it can be accessed serverside. So what you would want to do is make the code for the text-area, and rather set it to visibility: hidden; by default, or maybe display: none; so it pushes the rest down on appearing. I think it's best to use the html event onselect to launch the java script:http://www.w3schools.com/tags/ref_eventattributes.aspDo you have the script down from there? Link to comment Share on other sites More sharing options...
scale Posted November 13, 2006 Author Share Posted November 13, 2006 <script language="JavaScript" type="text/JavaScript">function hide(){document.getElementById('a_form').sap.style.display="none";document.getElementById('a_form').clickss.style.display="none";}function show(){document.getElementById('a_form').sap.style.display="inline";document.getElementById('a_form').clickss.style.display="inline";}function onFormSubmit(){var sap = document.getElementById('sap');if (sap.value =="") {alert("Please give us some comments");return false}}</script><form action="vote/sameVoteDetail.asp" method="post" id="a_form" target="_blank" onsubmit="java script:return onFormSubmit()"><table><tr><td><input type="radio" name="Vote" value="A" checked onClick="hide();return true;"></td><td>A</td></tr><tr><td><input type="radio" name="Vote" value="B" onClick="hide();return true;"></td><td>B</td></tr><tr><td><input type="radio" name="Vote" value="C" onClick="show();return true;" /></td><td>C</td></tr></table><br><img src="1.jpg" id="clickss" style="display:none;"><textarea rows="5" cols="18" name="sap" id="sap" style="background-color:white;display:none;" ></textarea><p><input type="Submit" value="Submit"/></input></form>when i hit A and b button, it wil come out with alert box. what's the problem? suppose the alert box come out only when user didn't key in data inside textarea.Thanks. Link to comment Share on other sites More sharing options...
whatabrother Posted November 13, 2006 Share Posted November 13, 2006 Hi all,i have 3 radio buttons(Yes, you do), which is(are) a, b and c, and 1 submit button.(Okay, It's intelligible so far) i want to do (You want to "do" a function? Strange...) a function, for example (Example of what?), if i click on a and b button, it show nothing(Yes, this is what your script does. You didn't want it to? Then what did you want it to do?). but if i click on c button, it appear a textarea, which ask me to key in some words. how to do the onclick function? (You used the onclick function. Why are you asking how to use it? It's in your source code. and how to alert user if not key in any words inside textarea? So you want the code to check for words inside of the textarea before it submits the page?Thanks. Link to comment Share on other sites More sharing options...
boen_robot Posted November 13, 2006 Share Posted November 13, 2006 Instead of usingonsubmit="java script:return onFormSubmit()"over the form, useonClick="java script:return onFormSubmit()"over the submit button. To be exact:<input type="Submit" value="Submit" onClick="java script:return onFormSubmit()"/> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now