Jump to content

Recommended Posts

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]

Link to comment
https://forums.phpfreaks.com/topic/188354-javascript-not-working-with-php/
Share on other sites

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 :).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.