harkly Posted January 13, 2010 Share Posted January 13, 2010 Not sure if this post belongs here but I am sure someone will let me know if not. I have this javascript which allows the user to make a selection and based on that selection other options drop down. However, when I start adding the if statements it will drop the options down but will not let you select one, instead it disappears as soon as you click on it. This code works fine : <fieldset id=\"wf_kids2Switch\" class=\"\"> <div id='aboutForm'> <span class='headerbox'> <b>Do you have kids</b> </span> <span class='textbox'> <input type='radio' name='sports' value='Bike' />No <br><input type='radio' name='sports' value='Bike' class=\"switch-b\" />Yes </span> </div> </fieldset> <fieldset id=\"wf-kids2\" class=\"offstate-b\"> <div id='aboutFormOff'> <input type='radio' name='kids' value='Bike' />At my home <br><input type='radio' name='kids' value='Bike' />Away from my home <br><input type='radio' name='kids' value='Bike' />Share homes </div> </fieldset> This is the code I need but is not working: <fieldset id=\"wf_kidsSwitch\" class=\"\"> <div id='aboutForm'> <span class='headerbox'>Do you have kids?</span> <span class='textbox'> \n"; if ($kids_have == 1){ echo " <input type='radio' name='kids_have' value='1' checked>No <br> \n";} else { echo " <input type='radio' name='kids_have' value='1'>No <br> \n";} if ($kids_have == 2){ echo " <input type='radio' name='kids_have' value='2' checked class=\"switch-a\">Yes <br> \n";} else { echo " <input type='radio' name='kids_have' value='2' class=\"switch-a\">Yes <br> \n";} echo " </span> </div> </fieldset> <fieldset id=\"wf-kids\" class=\"offstate-a\"> <div id='aboutFormOff'> \n"; if ($kids_have == 2){ echo " <input type='radio' name='kids_have' value='2' checked>At my home <br> \n";} else { echo " <input type='radio' name='kids_have' value='2'>At my home <br> \n";} if ($kids_have == 3){ echo " <input type='radio' name='kids_have' value='3' checked>Away from my home <br> \n";} else { echo " <input type='radio' name='kids_have' value='3'>Away from my home <br> \n";} if ($kids_have == 4){ echo " <input type='radio' name='kids_have' value='4' checked>Share homes <br> \n";} else { echo " <input type='radio' name='kids_have' value='4'>Share homes <br> \n";} echo " </div> </fieldset> The <script> tag <link href="wforms-jsonly.css" type="text/css" rel="alternate stylesheet" title="this stylesheet is activated by javascript" /> <script type="text/javascript" src="wforms.js" ></script> I attached the files need in the script, [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/188354-javascript-not-working-with-php/ Share on other sites More sharing options...
RussellReal Posted January 13, 2010 Share Posted January 13, 2010 php cannot execute after the php engine has exited and output the data to the client. Therefore php cannot work with Javascript, but you can echo javascript from php. You're probably going to want AJAX. more so XMLHttpRequest, and in your php you're going to echo out the stuff you want to show inside your select box, and with javascript you're gonna send what is selected and receive the new options and place it inside with a simple innerHtml call on the select box's html element. writing up your script to show you how would be a waste of time, however, I can point you in the right direction . Quote Link to comment https://forums.phpfreaks.com/topic/188354-javascript-not-working-with-php/#findComment-994345 Share on other sites More sharing options...
harkly Posted January 13, 2010 Author Share Posted January 13, 2010 Thanks! Can you point in the right direction? I really want this on my website. Quote Link to comment https://forums.phpfreaks.com/topic/188354-javascript-not-working-with-php/#findComment-994361 Share on other sites More sharing options...
RussellReal Posted January 13, 2010 Share Posted January 13, 2010 http://www.w3schools.com/Ajax/Default.Asp Quote Link to comment https://forums.phpfreaks.com/topic/188354-javascript-not-working-with-php/#findComment-994375 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.