Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Multiple echo on change?

    Hi Guys

    I have a problem on a form. The form allows users to select one of two options (A or B) from a drop down menu and the code echos the selection (to load different fields on a subsequent form). That works fine.

    The problem is, there is an input in the subsequent form which can be used in both selections (Input X) and the code is set to remember the user inputs if the user wants to go back and forth and edit the form. That works fine until the user decides to change their original selection from the original drop down box (e.g. from B to A) - the code remembers the user value of Input X when in fact, if a change is made to the drop down menu, I want Input X to be reset to 0.

    Hence is it possible to make the change on the drop down echo BOTH the selection made AND reset INPUT X to zero?

    An example of the current code is summarized below :

    Code:
    <td><select name="optionab" onChange = "submit_form(ad_create_form,'');">
    	  			<option value="a" selected><?=MSG_A;?></option>
    	  			<option value="b" <? echo ($details['optionab']=='B') ? 'selected' : ''; ?>><?=MSG_B;?></option>
    	  		</select></td>
    Ideally, I want to echo INPUT X = 0 on change but not sure how to do that?

    Thanks in advance

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    This all sounds like its a JS task, and not a PHP one.
    Back and forth between edit forms, are you referring to multiple windows / tabs for this? If so, that is definitely something PHP won't be working with. onchange is a client event; it is nothing that PHP is capable of intercepting. If you submit a form to PHP, you can use sessions to store the provided data, and then on a subsequent request you can lookup from session what was previously selected. But in my mind I picture this as having two forms open at the same time (or even just a form and a display), and you want to edit on the form and have it update on the other window. That is definitely requiring javascript, and I haven't a clue how that would even be approached.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    blackpool (03-21-2013)

  • #3
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    you could use $_SESSION variables to store things betwen pages then check if they match else unset them


    something like


    PHP Code:
    <?PHP
    session_start
    ()
    if (isset(
    $_POST['formsent'])){
        if ((isset(
    $_SESSION['optionab'])) && ($_SESSION['optionab'] == $_POST['optionab'])){
            
    //dropdown hasnt changed
        
    }else{
            
    //dropdown has changed
            
    $_SESSION['optionab'] == $_POST['optionab']; //update session variable
            
    $_POST['inputx'] = '';
        }
    }

    echo 
    '
    <form name="ad_create_form" method="POST" action="">
    <input type="hidden" name="formsent" value="sent">
    <select name="optionab" onChange = "submit_form(ad_create_form,'');">
          <option value="a" '
    . ($_SESSION['optionab']=='A') ? 'selected' ''; .'>'.MSG_A.'</option>
          <option value="b" '
    . ($_SESSION['optionab']=='B') ? 'selected' ''; .'>'.MSG_B.'</option>
    </select>
    <input type="text" name="inputx" value="'
    .$_POST['inputx'].'">
    </form>
    '
    ;
    Last edited by Arcticwarrio; 03-20-2013 at 11:49 PM.
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • Users who have thanked Arcticwarrio for this post:

    blackpool (03-21-2013)

  • #4
    New to the CF scene
    Join Date
    May 2011
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks Guys

    I was going to go down the session variable route but I have managed to resolve the issue by creating a formcheck procedure to create an error message to force Input X to be changed if the conflict arises.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •