JavaScript - Radio Button Onclick
hi guys
im trying to check whether a radio button is checked when i click it, but the javascript onlick event is not acting cool! when i click an unselected radio button i am informed that the unselected radio button i just clicked is in fact checked, when i should be getting the information the no, the radio button was not checked when i clicked it. any idea how to get the previous state of a radio button onclick? Similar TutorialsAs the code example below shows, I have three radio buttons that perform an javascript action when selected. Code: <script language="javascript"> function OnProductClick(product) { if (product.value == "Car") { // do something } else if (product.value == "Boat") { // do something else.. } else if (product.value == "Train") { // do else } } </script> <p>Select option <input type="radio" name="product" onclick="OnProductClick(this)" value="Car">Car</input> <input type="radio" name="product" onclick="OnProductClick(this)" value="Boat"> Boat</input> <input type="radio" name="product" onclick="OnProductClick(this)" value="Train">Train</input> </p> This setup is triggerred by a click, clicking multiple times on the same radio button will yield multiple calls to the OnProductClick function. This last part is what I would like to prevent. Say a user selects the option 'car' and then for some reason clicks on the same option again, this will lead to the OnProductClick function being executed twice. How can I prevent the second execution? Hi there, I'm soo stuck on particular piece of code.. You see i have 2 radio buttons with values 12hr and 24hr; on clicking any of the above the time format should change automatically. by default the time format comes in 12hr format against onload event of <body>. I've tried using javascript but this problem is persisting... Can anyone help me pleassssse.. I just started my javascript class two weeks ago and am having troubles already and my book is no help. My first assignment is having a list of country names and when you click the radio button next to the name the country flag pops up in a designated area for the image. I have tried a few different things but nothing is working. I have the list of countrys and the radio buttons but when i click the radio button the image doesn't pop up. Also, when i click another radio button they all stay selected. I am very new Beginner of Javascript.. My query is that 1)I have 2 radio buttons A and B 2)When I click A I want 2 dropdownbox and a button to be displayed 3)When I click B I want 2 dropdownbox to be displayed. 4)Both should be independent Plz tell me the code..for this Greetings! I'm trying to disable some form elements using the onclick from a radio input element. It ain't working so great! I googled around and finally scraped together some code that in theory 'I' think should work. I'm no javascript guru! It has to be some tiny tiny thing I'm missing. Here's my code and mind you this is a project in the making! I still have along way to go! Thanks for you time and help! Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Empty Page</title> <script type='text/javascript'> function setReadOnly(obj) { if(obj.value == "1") { document.shiftreport.artprogs.disabled = true; document.shiftreport.artprog_stat.disabled = true; } else { document.shiftreport.icprogs.disabled = true; document.shiftreport.icprog_stat.disabled = true; } } </script> </head> <body> <?php include_once('form_input_functions.php'); $artprog_status = array('none' => 'None', 'stopped' => 'Stopped', 'running' => 'Running', 'completed' => 'Completed', ); $artprog_wfls = array('no_job' => '------- select a job -------', 'ARTPROG/WFL/DAILY/BATCH' => 'ARTPROG/WFL/DAILY/BATCH', 'ARTPROG/WFL/OPERATIONS/IMAGE' => 'ARTPROG/WFL/OPERATIONS/IMAGE', 'ARTPROG/WFL/WKLY/BATCH' => 'ARTPROG/WFL/WKLY/BATCH', 'ARTPROG/WFL/DAILY/CLAIMS' => 'ARTPROG/WFL/DAILY/CLAIMS' ); $bllyprog_status = array('none' => 'None', 'stopped' => 'Stopped', 'running' => 'Running', 'completed' => 'Completed', ); $bllyprog_wfls = array('no_job' => '------- select a job -------', 'BLLYPROG/WFL/DAILY/SISCHEDPAY' => 'BLLYPROG/WFL/DAILY/SISCHEDPAY', 'BLLYPROG/WFL/DAILY/REPORTS' => 'BLLYPROG/WFL/DAILY/REPORTS', 'BLLYPROG/WFL/WKLY/REPORTS/GYPSUM' => 'BLLYPROG/WFL/WKLY/REPORTS/GYPSUM', '(BLPACK)BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP' => '(BLPACK)BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP', '$UTIL/O/AUDIT/CLOSE/BLLY' => '$UTIL/O/AUDIT/CLOSE/BLLY', 'DATASIWH/EXTRACTALL/DAILY/AUD/WFL' => 'DATASIWH/EXTRACTALL/DAILY/AUD/WFL', ); $sbwcprog_status = array('none' => 'None', 'stopped' => 'Stopped', 'running' => 'Running', 'completed' => 'Completed', ); $sbwcprog_wfls = array('no_job' => '------- select a job -------', 'WORKPROG/WFL/DAILY/WAREHOUSE' => 'WORKPROG/WFL/DAILY/WAREHOUSE', '(BLPACK)BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP' => '(BLPACK)BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP', '$UTIL/O/AUDIT/CLOSE/WORKCOMP' => '$UTIL/O/AUDIT/CLOSE/WORKCOMP' ); $tcsprog_status = array('none' => 'None', 'stopped' => 'Stopped', 'running' => 'Running', 'completed' => 'Completed', ); $tcsprog_wfls = array ('no_job' => '------- select a job -------', 'TCS/WFL/DAILY/BATCH' => 'TCS/WFL/DAILY/BATCH', 'BLPROG/WFL/COPY/REMOVE/GLCHECKS' => 'BLPROG/WFL/COPY/REMOVE/GLCHECKS' ); $icprog_status = array('none' => 'None', 'stopped' => 'Stopped', 'running' => 'Running', 'completed' => 'Completed', ); $icprog_wfls = array ('no_job' => '------- select a job -------', 'BLPROG/WFL/DAILY/INDCONT' => 'BLPROG/WFL/DAILY/INDCONT', 'INDCON/WFL/PRINT/IDCARDS' => 'INDCON/WFL/PRINT/IDCARDS', 'BLPROG/WFL/BATCH/NEWYORK/STATE-REPORT' => 'BLPROG/WFL/BATCH/NEWYORK/STATE-REPORT' ); $truckprog_status = array('none' => 'None', 'stopped' => 'Stopped', 'running' => 'Running', 'completed' => 'Completed', ); $truckprog_wfls = array('no_job' => '------- select a job -------', 'TRUCKPROG/WFL/DAILY/TKINTMARSH' => 'TRUCKPROG/WFL/DAILY/TKINTMARSH', 'TRUCKPROG/WFL/DAILY/TKINTERNET' => 'TRUCKPROG/WFL/DAILY/TKINTERNET', 'TRUCKPROG/WFL/DAILY/BATCH' => 'TRUCKPROG/WFL/DAILY/BATCH', 'TRUCKPROG/WFL/DAILY/TKSCHEDPAY' => 'TRUCKPROG/WFL/DAILY/TKSCHEDPAY', 'TRUCKPROG/WFL/DAILY/REPORTS' => 'TRUCKPROG/WFL/DAILY/REPORTS', 'BLPROG/WFL/DAILY/CLAIMS' => 'BLPROG/WFL/DAILY/CLAIMS', 'TRUCKPROG/WFL/DAILY/AUDIT/PREMIUM' => 'TRUCKPROG/WFL/DAILY/AUDIT/PREMIUM', 'TRUCKPROG/WFL/DAILY/BALRPT' => 'TRUCKPROG/WFL/DAILY/BALRPT', 'PROG-MEDICAL/WFL/DAILY/PMCLMEXT' => 'PROG-MEDICAL/WFL/DAILY/PMCLMEXT', 'AGPROG/WFL/DAILY/AGNUCOPREM' => 'AGPROG/WFL/DAILY/AGNUCOPREM', 'BL/WFL/WKLY/FEDEX/0005' => 'BL/WFL/WKLY/FEDEX/0005', 'TRUCKPROG/WFL/WKLY/DE542' => 'TRUCKPROG/WFL/WKLY/DE542', 'TRUCKPROG/WFL/WKLY/FDXDISAB' => 'TRUCKPROG/WFL/WKLY/FDXDISAB', 'TRUCKPROG/WFL/WKLY/FDXDISERR' => 'TRUCKPROG/WFL/WKLY/FDXDISERR', 'BL/WFL/ONLINE/DUMP/TRUCKING' => 'BL/WFL/ONLINE/DUMP/TRUCKING', 'DATATKWH/EXTRACTALL/DAILY/WFL' => 'DATATKWH/EXTRACTALL/DAILY/WFL', '(BLPACK)BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP' => '(BLPACK)BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP' ); $smallprog_status = array('none' => 'None', 'stopped' => 'Stopped', 'running' => 'Running', 'completed' => 'Completed', ); $smallprog_wfls = array('no_job' => '------- select a job -------', 'SMALLPROG/WFL/DAILY/BATCH' => 'SMALLPROG/WFL/DAILY/BATCH', 'SMALLPROG/WFL/DAILY/CERTS' => 'SMALLPROG/WFL/DAILY/CERTS', 'SMALLPROG/WFL/OPERATIONS/PRINT' => 'SMALLPROG/WFL/OPERATIONS/PRINT', 'SMALLPROG/WFL/WKLY/BATCH' => 'SMALLPROG/WFL/WKLY/BATCH', 'SFCLAIMS/WFL/DAILY/DWHCLAIMS' => 'SFCLAIMS/WFL/DAILY/DWHCLAIMS', 'SFCLAIMS/WFL/DAILY/REPORTS' => 'SFCLAIMS/WFL/DAILY/REPORTS', 'SFCLAIMS/WFL/WEEKLY/REPORTS' => 'SFCLAIMS/WFL/WEEKLY/REPORTS', 'BL/WFL/ONLINE/DUMP/SFDB/1WORKER' => 'BL/WFL/ONLINE/DUMP/SFDB/1WORKER', '$UTIL/O/AUDIT/CLOSE/SFDB' => '$UTIL/O/AUDIT/CLOSE/SFDB', 'DATASFWH/EXTRACTALL/DAILY/WFL' => 'DATASFWH/EXTRACTALL/DAILY/WFL', '(BLPACK)BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP' => '(BLPACK)BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP' ); $persauto_status = array('none' => 'None', 'stopped' => 'Stopped', 'running' => 'Running', 'completed' => 'Completed', ); $persauto_wfls = array('no_job' => '------- select a job -------', 'PERSAUTO/WFL/DAILY/BATCH' => 'PERSAUTO/WFL/DAILY/BATCH', 'PERSAUTO/WFL/OPERATIONS/IMAGE' => 'PERSAUTO/WFL/OPERATIONS/IMAGE', 'PERSAUTO/WFL/OPERATIONS/PRINT' => 'PERSAUTO/WFL/OPERATIONS/PRINT', 'PERSAUTO/WFL/WKLY/BATCH' => 'PERSAUTO/WFL/WKLY/BATCH', 'PERSAUTO/WFL/DAILY/CLAIMS' => 'PERSAUTO/WFL/DAILY/CLAIMS', 'BL/WFL/ONLINE/DUMP/DB1/1WORKER/FULL' => 'BL/WFL/ONLINE/DUMP/DB1/1WORKER/FULL', '$UTIL/O/AUDIT/CLOSE/DB1' => '$UTIL/O/AUDIT/CLOSE/DB1', 'DATAWH/EXTRACTALL/DAILY/WFL' => 'DATAWH/EXTRACTALL/DAILY/WFL', 'BL/WFL/OFFLINE/DUMP/WAREHOUSE' => 'BL/WFL/OFFLINE/DUMP/WAREHOUSE' ); $isoprog_status = array('none' => 'None', 'stopped' => 'Stopped', 'running' => 'Running', 'completed' => 'Completed', ); $isoprog_wfls = array('no_job' => '------- select a job -------', 'ISOPROG/WFL/BATCH/ISOSAGDAILY' => 'ISOPROG/WFL/BATCH/ISOSAGDAILY' ); $bkuplive_status = array('none' => 'None', 'stopped' => 'Stopped', 'running' => 'Running', 'completed' => 'Completed', ); $bkuplive_wfls = array('no_job' => '------- select a job -------', 'BL/WFL/ONLINE/DUMP/BLDB' => 'BL/WFL/ONLINE/DUMP/BLDB', '(BLPACK)BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP' => '(BLPACK)BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP', '$UTIL/O/AUDIT/CLOSE/BLDB' => '$UTIL/O/AUDIT/CLOSE/BLDB', 'DATARDWH/EXTRACTALL/DAILY/REIN/WFL' => 'DATARDWH/EXTRACTALL/DAILY/REIN/WFL', '(BLPACK)BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP' => '(BLPACK)BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP', 'BL/WFL/FICHE/DISK' => 'BL/WFL/FICHE/DISK' ); $testsite_status = array('none' => 'None', 'stopped' => 'Stopped', 'running' => 'Running', 'completed' => 'Completed', ); $testsite_wfls = array('no_job' => '------- select a job -------', 'WFL/TESTLYON/DATABASE/ONLINE/DISABLE' => 'WFL/TESTLYON/DATABASE/ONLINE/DISABLE', 'UTIL/WFL/REMOVE/TESTLYON/BDFILES' => 'UTIL/WFL/REMOVE/TESTLYON/BDFILES', 'BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP' => 'BALDLYON/WFL/BLPACK/ARCHIVEANDBACKUP' ); ?> <form method="POST" name="shiftreport" action="<?php print $_SERVER['PHP_SELF']; ?>"> <p>1st Shift <?php input_radiocheck('radio','shift','0','1','1'); ?></p> <p>2st Shift <?php input_radiocheck('radio','shift','0','2','1'); ?></p> <p>3st Shift <?php input_radiocheck('radio','shift','0','3','1'); ?></p> <table> <thead> <tr> <th>Application</th> <th>Job Stream</th> <th>Status</th> </tr> </thead> <tbody> <tr> <td>ARTISAN</td> <td> <?php input_select('artprogs',$artprog_wfls['no_job'], $GLOBALS['artprog_wfls'], '390px'); ?> </td> <td> <?php input_select('artprog_stat', $artprog_status['none'] , $GLOBALS['artprog_status']); ?> </td> </tr> <tr> <td>SELF INSURED</td> <td> <?php input_select('bllyprogs',$bllyprog_wfls['no_job'], $GLOBALS['bllyprog_wfls'], '390px'); ?> </td> <td> <?php input_select('bllyprog_stat', $bllyprog_status['none'] , $GLOBALS['bllyprog_status']); ?> </td> </tr> <tr> <td>SBWC</td> <td> <?php input_select('sbwcprogs',$sbwcprog_wfls['no_job'],$GLOBALS['sbwcprog_wfls'], '390px'); ?> </td> <td> <?php input_select('sbwcprog_stat', $sbwcprog_status['none'] , $GLOBALS['sbwcprog_status']); ?> </td> </tr> <tr> <td>TCS</td> <td> <?php input_select('tcsprogs',$tcsprog_wfls['no_job'], $GLOBALS['tcsprog_wfls'], '390px'); ?> </td> <td> <?php input_select('tcsprog_stat', $tcsprog_status['none'] , $GLOBALS['tcsprog_status']); ?> </td> </tr> <tr> <td>IC</td> <td> <?php input_select('icprogs',$icprog_wfls['no_job'], $GLOBALS['icprog_wfls'], '390px'); ?> </td> <td> <?php input_select('icprog_stat', $icprog_status['none'] , $GLOBALS['icprog_status']); ?> </td> </tr> <tr> <td>TRUCKING</td> <td> <?php input_select('truckprogs',$truckprog_wfls['no_job'], $GLOBALS['truckprog_wfls'], '390px'); ?> </td> <td> <?php input_select('truckprog_stat', $truckprog_status['none'] , $GLOBALS['truckprog_status']); ?> </td> </tr> <tr> <td>SMALL FLEET</td> <td> <?php input_select('smallprogs',$smallprog_wfls['no_job'], $GLOBALS['smallprog_wfls'], '390px'); ?> </td> <td> <?php input_select('smallprog_stat', $smallprog_status['none'] , $GLOBALS['smallprog_status']); ?> </td> </tr> <tr> <td>PERSONAL AUTO</td> <td> <?php input_select('persauto',$persauto_wfls['no_job'], $GLOBALS['persauto_wfls'], '390px'); ?> </td> <td> <?php input_select('persauto_stat', $persauto_status['none'] , $GLOBALS['persauto_status']); ?> </td> </tr> <tr> <td>ISO</td> <td> <?php input_select('isoprog',$isoprog_wfls['no_job'], $GLOBALS['isoprog_wfls'], '390px'); ?> </td> <td> <?php input_select('isoprog_stat', $isoprog_status['none'] , $GLOBALS['isoprog_status']); ?> </td> </tr> <tr> <td>BACKUPS LIVE</td> <td> <?php input_select('bkuplive',$bkuplive_wfls['no_job'], $GLOBALS['bkuplive_wfls'], '390px'); ?> </td> <td> <?php input_select('bkuplive_stat', $bkuplive_status['none'] , $GLOBALS['bkuplive_status']); ?> </td> </tr> <tr> <td>TEST SITE INSTRUCTIONS</td> <td> <?php input_select('testsite',$testsite_wfls['no_job'], $GLOBALS['testsite_wfls'], '390px'); ?> </td> <td> <?php input_select('testsite_stat', $testsite_status['none'] , $GLOBALS['testsite_status']); ?> </td> </tr> </tbody> </table> </form> </body> </html> The included functions file that I didn't include is below: Code: <?php function input_text($element_name, $value) { print '<input type="text" name="' . $element_name . '" value="'; print htmlentities($values[$element_name]) . '">'; } function input_submit($element_name,$label) { print '<input type="submit" name="' . $element_name .'" value="'; print htmlentities($label) .'"/>'; } function input_textarea($element_name,$values) { print '<textarea name="' . $element_name . '">'; print htmlentities($values[$element_name]) . '</textarea>'; } function input_radiocheck($type,$element_name,$values,$element_value,$clicker = '0') { print '<input type="' . $type . '" name="' . $element_name . '" value="' . $element_value . '" '; if ($element_value == $values[$element_name]) { print ' checked="checked"'; } if ($clicker == '1') print ' onclick="setReadOnly(this)"'; print '/>'; } function input_select($element_name, $selected, $options, $drop_width = '100px', $multiple = false) { print '<select style="width:' . $drop_width . ';" name="' . $element_name; if ($multiple) { print '[]" multiple="multiple'; } print '">'; $selected_options = array(); if ($multiple) { foreach ($selected[$element_name] as $val) { $selected_options[$val] = true; } } else { $selected_options[ $selected[$element_name] ] = true; } foreach ($options as $option => $label) { print '<option value="' . htmlentities($option) . '"'; if (isset($selected_options[$option])) { print ' selected="selected"'; } print '>' . htmlentities($label) . '</option>'; } print '</select>'; } ?> I have 4 rows in a table. Each row consist of 4 radio buttons. Each radio button per row has different values in it but has the same name (group) ex: <input type="radio" name="a" value="1"> <input type="radio" name="a" value="2"> <input type="radio" name="a" value="3"> <input type="radio" name="a" value="4"> <input type="radio" name="b" value="1"> <input type="radio" name="b" value="2"> <input type="radio" name="b" value="3"> <input type="radio" name="b" value="4"> and so on.. If I click radio button A with value 2, I want to output the total at the bottom as "2".. Also, if I click radio button B with value 3, I want to output the total of A and B as 5 and so on.. How can I automatically calculate the answer based on which radio button was click? update: I got my answer from this site: http://stackoverflow.com/questions/1...s-using-jquery Hi all, I have a problem in javascript , ajax and jsp. Please see this url http://xil.co.in/print_screen_2.JPG. I am working on this form. There are sum buttons (like submit , add ,edit at bottom of this page , but not visible in printscreen). On click of a radio button on left side , form fields on right side and small table on right bottom is gettig populated. The table on right bottom , is actually the eligibility criteria associated with the record whose radio was clicked on left . On clicking radio of this record(right side) , I want to populate its values in the above text boxes present right in front of text "Eligibility". During the whole click process (clicking the left and right radio button ) page should not get refreshed. I am able to show records on left side by iterating over a resultset (in jsp) and able to populate field on right side also, but have no idea how to populate table on right bottom dynamically such that I can handle onclick event on its radio button. Pls tell me how to achieve this. Thanks in advance for any help. Hi, I have 4 radio buttons with separate div(s) I need to click on each radio button to show particular div(s) but I am not getting correct result Lease help HTML Code ---------- <input type="radio" name="list_prefer_c" id="list_prefer_c" value="1" onClick=\"get_radio_value(1);\" > <input type="radio" name="list_prefer_c" id="list_prefer_c" value="2" onClick=\"get_radio_value(2);\" > <input type="radio" name="list_prefer_c" id="list_prefer_c" value="3" onClick=\"get_radio_value(3);\" > <input type="radio" name="list_prefer_c" id="list_prefer_c" value="4" onClick=\"get_radio_value(4);\" > <div id="div1" style="display:none"> Facilities Management </div> <div id="div2" style="display:none"> <div style="font-weight:bold">Facilities Management, Contracting, MEP, Hydraulic Valves, trading etc… </div> <div id="div3" style="background-color:#00B0F0;display:none"> Facilities Management, Contracting, MEP, Hydraulic Valves, trading etc… </div> <div id="div4" style="background-color:#00B0F0;display:none"> Facilities Management,Contracting, MEP, Hydraulic Valves, Plumping, LV Switching, Fire alarm & Fire Fighting Trading etc… </div> JSCode -------- function toggleLayer(val) { if(val == 1) { document.getElementById('div1').style.display = 'block'; document.getElementById('div2').style.display = 'none'; document.getElementById('div3').style.display = 'none'; document.getElementById('div4').style.display = 'none'; } else if(val == 2) { document.getElementById('div1').style.display = 'none'; document.getElementById('div2').style.display = 'block'; document.getElementById('div3').style.display = 'none'; document.getElementById('div4').style.display = 'none'; } else if(val == 3) { document.getElementById('div1').style.display = 'none'; document.getElementById('div2').style.display = 'none'; document.getElementById('div3').style.display = 'block'; document.getElementById('div4').style.display = 'none'; } else if(val == 4) { document.getElementById('div1').style.display = 'none'; document.getElementById('div2').style.display = 'none'; document.getElementById('div3').style.display = 'none'; document.getElementById('div4').style.display = 'block'; } } All, I have the following code: Code: <form action="" name="myform" method="post"> <input type="hidden" id="picimages" name="picimages" value="<?php echo $resultsetstory['bigger_id']; ?>" /> <p> <label> <input type="radio" id="picimages" name="picimages" value="<?php echo $resultsetstory['picture_id']; ?>" /> <?php if($resultsetstory['title']<>""){ echo $resultsetstory['title']; }else{ echo "Image 1"; } ?> </label> <br /> <label> <input type="radio" id="picimages" name="picimages" value="<?php echo $resultsetpic2['picture_id']; ?>" /> <?php if($resultsetpic2['title']<>""){ echo $resultsetpic2['title']; }else{ echo "Image 2"; } ?> </label> <br /> <input name="submit" type="button" value="Vote!" onclick="javascript:voteupdate(this.myform);"/> </p> </form> When I submit this, it goes to this function: Code: function voteupdate(obj) { var poststr = "picimage=" + document.getElementById("picimage").value + "&bigger_id=" + encodeURI( document.getElementById("bigger_id").value ); alert(poststr); makePOSTRequest('voteresults.php', poststr); } However I can't get the value of the radio group for the one that is selected. Can someone see what is wrong? Thanks. All: I need some help with a radio button code. It seems simple but I am really new at JavaScript so I need help. I have created a JavaScript code that has three radio buttons (High, Medium, and Low). When you click on high two text boxes appear so that an email address can be added. What I need help with is making the text boxes disappear if someone accidentally click high and then went back to low or medium. Currently the High button stays clicked and the text boxes still show. Any help would be great. Thanks, Stephen Code: <script type="text/javascript"> function showHide(el){ obj = document.getElementById(el).style; (obj.display == 'none')? obj.display = 'block' : obj.display = 'none'; } </script> <form id="form1" name="form1" method="post" action=""> <label> <input type="Checkbox" name="High" value="High" onclick="showHide('group1')" /> High </label> <label> <input type="Checkbox" name="Medium" value="Button" /> Mediun </label> <label> <input type="Checkbox" name="Medium" value="Button" /> Low </label> <p id="group1" style="display: none;"> <label> <b>friend1  </b><input type="Text" name="textGroup1" value="@gmail.com" /> <br/> </label> <br /> <label> <b>friend2  </b><input type="text" name="textGroup1" value="@gmail.com" /> </label> </p> </form> I don't exactly know how to word my issue. Basically, I need it so that if a user selects 'option1' in the group 'group1' when they go to 'group2' is only gives them a certain selection to choose from. If they choose 'option2' in 'group1' they will get a different set to choose from. My main dilemma is it must do this without them having to submit. I'm a newbie Javascript coder and I've run into a little problem. I hope someone can help me with it. The idea is that I've got a bunch of images, and I want one thing to fire when left-clicking them and a different thing when right-clicking. For the purpose of this thread I've replaced the 'things' with alerts. this is the part that gets added to the images (called 'plaatje'): Code: plaatje.onclick = klik; this is the function that gets executed when clicked. Code: function klik(event) { var fotoID = event.target.id; if (event.button == 0) { alert("Left click on " + fotoID + "!"); } else if (event.button == 2) { event.preventDefault(); alert("Right click on " + fotoID + "!"); } } I've added the "event.preventDefault();" part because I was told that would prevent the right-click menu from popping up. The problem is that the left-click part of the code works perfectly, but the right-click part does nothing. The right-click menu comes up as normal and the alert never shows. Can anyone tell me what I'm doing wrong? What have I done wrong here? <INPUT id="purchase" onclick="document.getElementById("purchase").disabled = true;" type="submit" value="PURCHASE"> I'm trying to get a submit button to open a thank you page I created (i.e. thankyou.html) only after the user has filled out a series of questions for a form. If they don't fill out the required information, a pop up box informs them to fill out the section (this I have accomplished). I cannot get the submit button to not work if the fields are left un-answered. Can you guys help? Thanks for you help. -------------------------------------------------------------------------- This is what I have so far: <title>Customer Demographic Data Form</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" ></meta> <style type="text/css"> body { font-family: Times New Roman; color: navy; background-color: #CCC } h1, h2, h5 { font-family: Times New Roman; color: black } body,td,th { color: #000; font-family: Times New Roman, Times, serif; } h1 { color: #000; } h2 { color: #000; } h5 { color: #000; } a { font-family: Times New Roman, Times, serif; } h1,h2,h3,h4,h5,h6 { font-family: Times New Roman, Times, serif; } </style> <script type="text/javascript"> function checkForNumber(fieldValue) { var numberCheck = isNaN(fieldValue); if (numberCheck == true) { window.alert("Please enter a numeric value!"); return false; } } function confirmSubmit() { var email = document.forms[0].email.value; if (document.forms[0].fname.value == "" || document.forms[0].lname.value == "") { window.alert("Please enter your first and last name."); document.forms[0].lname.focus(); return false; } else if (document.forms[0].address1.value == "" && document.forms[0].email.value == "") { window.alert("Please enter your Mailing Address or Email Address!"); document.forms[0].address1.focus(); return false; } else if (email.indexOf("@") == -1 && document.forms[0].email.value != "") { window.alert("Please enter a valid e-mail address."); document.forms[0].email.focus(); return false; } else if (email.indexOf(".") == -1 && document.forms[0].email.value != "") { window.alert("Please enter a valid e-mail address."); document.forms[0].email.focus(); return false; } else if(document.forms[0].city.value == '') { window.alert("Please enter your City"); document.forms[0].city.focus(); return false; } else if(document.forms[0].state.value == '') { window.alert("Please enter your State"); document.forms[0].state.focus(); return false; } else if(document.forms[0].zip.value == '') { window.alert("Please enter your Zip Code"); document.forms[0].zip.focus(); return false; } checkCookie() } function checkCookie() { var formInfo = decodeURI(document.cookie); var userInfo = formInfo.split("; "); var lname = userInfo[0].split("="); var fname = userInfo[1].split("="); if (lname[1] == document.forms[0].lname.value && fname[1] == document.forms[0].fname.value) { this.close(true); window.open("FormDenied.html"); return false; } else { setCookie(); return true; } } function setCookie() { var expiresDate = new Date(); expiresDate.setFullYear(expiresDate.getFullYear() + 1); document.cookie = encodeURI("lname=" + document.forms[0].lname.value) + "; expires=" + expiresDate.toUTCString(); document.cookie = encodeURI("fname=" + document.forms[0].fname.value) + "; expires=" + expiresDate.toUTCString(); window.alert("Your information has been saved."); } </script> </head> <body> <p> </p> <h1 align="left" style="text-align: left">Kudler Fine Foods contact form</h1> <form action="" method="get" enctype="application/x-www-form-urlencoded" onsubmit="return confirmSubmit();" onreset="return confirmReset();" > <blockquote> <h2><u>Name</u></h2> <p> <input type="text" name="fname" id="fname" size="25" /> <label for="fname"><strong>First Name</strong><br> <br> </label> <input type="text" name="lname" id="lname" size="15" /> <strong>Last Name</strong></p> <h2>---------------------------------------<br> <u>Address</u> </h2> <p> <input type="text" name="address1" id="address1" size="30" /> <label for="address1"><strong>Address Line 1</strong></label> </p> <p> <input type="text" name="address2" id="address2" size="20" /> <strong>Address Line 2<br> <br> </strong> <input type="text" name="city" id="city" size="20" /> <strong>City</strong> </p> <p> <input type="text" name="state" id="state" size="2" /> <label for="state2"><strong>State</strong></label> </p> <p> <input type="text" name="zip" id="zip" size="10" maxlength="10" onChange="return checkForNumber(this.value);" /> <label for="zip2"><strong>Zip Code</strong></label> </p> <h2>--------------------------------------- </h2> <h2> <u>Other Information</u></h2> <table> <tr> <td width=300><strong>Telephone</strong></td> <td width=300><p><strong>Email address:</strong></p></td> </tr> <tr> <td> <input type="text" name="area" id="area" size="3" maxlength="3" onChange="return checkForNumber(this.value);" /> <input type="text" name="exchange" id="exchange" size="3" maxlength="3" onChange="return checkForNumber(this.value);" /> <input type="text" name="phone" id="phone" size="4" maxlength="4" onChange="return checkForNumber(this.value);" /></td> <td> <input type="text" name="email" id="email" size="30" /></td> </tr> </table> </blockquote> <h5> </h5> <blockquote><blockquote> <h3 align="center"> <input name="Submit" type="button" </h3> </blockquote> </blockquote> </form> </body> </html> How do I change the Button's value onClick? I want it to initially be "Read More" and then change to "Show Less" Code: <script type="text/javascript"> function toggleMe(a){ var e=document.getElementById(a); if(!e)return true; if(e.style.display=="none"){ e.style.display="block" } else{ e.style.display="none" } return true; } </script> <div>Why are we going to stop making investments in companies like this?</div> <span id="obamaenergyapril212011" style="display:none;"> END 12:50 P.M. PDT</span> <input type="button" name="obama" onclick="return toggleMe('obamaenergyapril212011')" value="Read/Hide More" > I am ignorant in java scripting. I want to use the following java script to create the radiobutton in obiee reporting. This java script will change the regular prompt to radio button,however I do not know how to debug if it is working. Waiting for kind reply. Anil PHP Code: <script type="text/javascript"> function getElementsByClass(searchClass,node,tag) { var classElements = new Array(); if ( node == null ) node = document; if ( tag == null ) tag = '*'; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); for (i = 0, j = 0; i < elsLen; i++) { if ( pattern.test(els[i].className) ) { classElements[j] = els[i]; j++; } } return classElements; } var tables = getElementsByClass('DashboardPromptViewTable',null, 'table'); for (var table = 0; table < tables.length; table++){ var stringFunc = ''; var selects = tables[table].getElementsByTagName('select'); if ( selects.length == undefined || selects.length == 0 || selects[0].name === 'Match'){ if (debug === 1) { document.write("No selects found. Continue to next record."+"<BR>");} continue; // This DB Prompt doesn't have any select statements } var spans = getElementsByClass('minibuttonOn',tables[table],'span'); spans[0].style.display="none"; stringFunc = String(spans[0].getElementsByTagName('a')[0].onclick); stringFunc = stringFunc.substr(stringFunc.indexOf('{')+1, stringFunc.length - 2 - stringFunc.indexOf('{')); for (var s =0; s < selects.length; s++){ var new_form = document.createElement('form'); var options = selects[s].getElementsByTagName('option'); new_form.name = selects[s].name+"_radio"; new_form.id = selects[s].id+"_radio"; for (var o=0; o<options.length; o++) { var new_input = document.createElement('input'); new_input.type = 'radio'; new_input.value = options[o].value; new_input.name = selects[s].name+"_radio"; if(selects[s].selectedIndex == o){ new_input.checked = true; } var onClickStringFunc = "var sel = document.getElementById(this.name.substr(0,this.name.length-6));" + "if ( sel == null){"+ "return;"+ "}"+ "var opts = sel.getElementsByTagName('option');"+ "for( var opt = 0; opt < opts.length; opt++){"+ "if( opts[opt].value == this.value){"+ "sel.selectedIndex = opt;"+ "}"+ "}"; new_input.onclick = new Function(onClickStringFunc + stringFunc); var new_text = document.createTextNode(options[o].innerHTML); new_form.appendChild(new_input); new_form.appendChild(new_text); } // end options for loop selects[s].parentNode.insertBefore(new_form,selects[s]); selects[s].style.display="none"; } // end selects for loop } // end table foor loop </script> Hi, I am trying to use the radio button to display the information for the users. For example, when I click radio button "1", the form should display 1 text box each for first name, last name and so on. When the user clicks on radio button 2, there should be text boxes displayed for user 1 and user 2 to enter their info(first name, last name and so on). I looked at the forum, but couldn't find something similiar.Please advise. Something like ================================ Number of Users 1 2 3 # if radio button 2 is selected then User 1 First Name Last Name User 2 First Name Last Name ================================ The code is as below: <html> <head> <script type="text/javascript"> function showUser() { for(i=0;i<document.form.users.length;i++) { if (document.form.users[i].checked) val=parseInt(document.form.users[i].value); for(j=0;j<=val;j++) { document.form.write("<table cellSpacing=1 cellPadding=0 width=600 border=0>"); document.form.write("<tr> <td width='20%' align='right'><font color="#660000"><b>First Name: </b></font></td>"); document.form.write("<td><input type='text' name='fname1' size='25' maxlength='25'></td></tr>"); document.form.write("<tr><td width='20%' align='right'><font color="#660000"><b>Last Name: </b></font></td>"); document.form.write("<td><input type='text' name='lname1' size='25'maxlength='25'></td></tr>"); document.form.write("</table>"); } } } </script> </head> <form> Check the number of users to display additional input fields.<br><br> <input type="radio" name="users" value="1" onclick = "showUser()"/> 1<br/> <input type="radio" name="users" value="2" onclick = "showUser()"/>2 <br/> <input type="radio" name="users" value="3" onclick = "showUser()"/>3 <br/> </form> </html> ======================================================== Thanks in advance. Hello, I have a form which can be saved (using a database) and later edited. When restoring data to the form , text fields are easy. There is a simple (existing) JavaScript which restores an option that was selected from a pull-down (select one) menu: Code: for (var q=0;q<document.Simple.Color.options.length;q++) { if (document.Simple.Color.options[q].value == document.Restored.Color.value) { document.Simple.Color.options[q]. selected = true; break; } I'm trying to make it work to restore a value to a radio button as well... but no luck: Code: for (var q=0;q<document.Simple.Color.options.length;q++) { if (document.Simple.Color.options[q].value == document.Restored.Color.value) { document.Simple.Color.options[q]. checked = true; break; } Any ideas? Thanks in advance. ~Wayne Hello I am very new to Java Script. I am working on a website which requires me to use it. The site is selling items that are priced depending on the size. There are 6 fixed sizes for the width and the length can come in any size 1 through 200. So that will be user input on the length and radio buttons on the width. I am trying to have the user put in the length and click a radio button for width and then calculate the price by multiplying them. I am trying to get 1 price to display right now just to test it but I can't figure out why it isn't working. Again I am fairly new at this so there might be multiple problems with my code. Thanks in advance for the help. Code: <script type = "text/javascript"> function buttoncheck(){ var selection1 = document.menu.selection; if (selection1 == 60) {choice1()} if (selection1 == 50) {choice2()} if (selection1 == 25) {choice3()} if (selection1 == 10) {choice4()} if (selection1 == 4) {choice5()} if (selection1 == 2) {choice6()} function choice1(){ var len = Number(document.getElementById("length").value) || 0; var area1 = selection1 * len; var cost = 0; if (area1 == 60) { cost = 60} return cost; document.getElementById("TotalCost").innerHTML = "$" + cost.toFixed(2); } Code: <h4 class="auto-style3">Pricing Calculator:</h4> <p> <form method="post"> <div class="auto-style1"> <span class="auto-style2">LENGTH:</span> <input name="length" type="text" id="length" /><br /> </form> <div class="auto-style1"> <form name="menu"> <input type="radio" value="60" name="selection">60 inch</input> <input type="radio" value="50" name="selection">50 inch</input> <input type="radio" value="25" name="selection">25 inch</input> <input type="radio" value="10" name="selection">10 inch</input> <input type="radio" value="4" name="selection">4 inch label</input> <input type="radio" value="2" name="selection">2 inch label</input> </form> </div> <p class="auto-style1"> <input type="button" value="Calculate" onClick="buttoncheck()" </p> </p> <p> </p> <span id="TotalCost"></span><script type = "text/javascript"> document.getElementById("TotalCost").innerHTML = "Total cost is $" + cost.toFixed(2); Hello, I am trying to implement a radio button option so that users can search specific sites such as google, yahoo, or bing from input box. Here's my code. Please help. <script type="text/javascript"> <!-- function goSearch(){ //search according to checked radio button } --> </script> <h1>Search Option</h1><br /> <input type="radio" name="search" id="google"/><a href="http://www.google.com" rel="nofollow" target="_blank"><img src="images/google.jpg" /></a> <input type="radio" name="search" id="yahoo"/><a href="http://www.yahoo.com" rel="nofollow" target="_blank"><img src="images/yahoo.jpg" /> </a> <input type="radio" name="search" id="bing" /><a href="http://www.bing.com" rel="nofollow" target="_blank"><img src="images/bing.jpg" /> </a> <br /><br /> <form method="get" action="goSearch()" rel="nofollow" target="_blank"> <div style="border:1px solid black;padding:4px;width:20em;"> <table border="0" cellpadding="0"> <tr> <td> <input type="text" name="q" size="25" maxlength="255" value="" /> <input type="submit" value="Search" /> </td> </tr> </table> </div> </form> |