Javascript onChange event in PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • countocram
    New Member
    • Sep 2006
    • 3

    Javascript onChange event in PHP

    hi! Im having a problem retaining the inputs on my text fields. When i selected an option from a dropdown list with an onChange=locati on.. event. What happen is that, everytime I choose an option the page will reload then the inputs on my text field will disappear...

    sample HTML:

    <INPUT type="text" name="help_titl e" size="50">
    <textarea cols="50" rows="15" name="help_cont ent"></textarea>

    <select name="main_topi c" onChange="locat ion='help_add_f orm.php?help_id ='+this.options[this.selectedIn dex].value+'&help_s ub_id='">
    <option value="option"> option1</option>
    </select>


    my question is, how can i retain the values on the input fields when an onchange event was triggered?

    hope to hear from you guys! thanks!
  • PLA
    New Member
    • Aug 2006
    • 44

    #2
    Did you try to use a onchange="myfor m.submit();" instead ?
    All values will be in the request, then you can give it back in the form.

    <INPUT type="text" name="help_titl e" size="50" value="OldText" >

    Comment

    • countocram
      New Member
      • Sep 2006
      • 3

      #3
      Originally posted by PLA
      Did you try to use a onchange="myfor m.submit();" instead ?
      All values will be in the request, then you can give it back in the form.

      <INPUT type="text" name="help_titl e" size="50" value="OldText" >
      Thanks for your reply PLA, but how can i pass on the value of my location to the address bar if i will use myform.submit() ;

      I'm sorry asking a lot, im new on these stuffs...

      Comment

      • PLA
        New Member
        • Aug 2006
        • 44

        #4
        Originally posted by countocram
        Thanks for your reply PLA, but how can i pass on the value of my location to the address bar if i will use myform.submit() ;

        I'm sorry asking a lot, im new on these stuffs...
        Code:
        <html>
         <head>
          </head>
          <body>
            <form action="test.php" method="PUT" name="myform">
              <input type="text" name="help_title" size="50" value=<?print $help_title?>>
              <textarea cols="50" rows="15" name="help_content"><?print $help_content?></textarea>
              <select name="main_topic" onChange="myform.submit();">
                <option value="option1" <?if ($main_topic == "option1") print selected?>>option1</option>
                <option value="option2" <?if ($main_topic == "option2") print selected?>>option2</option>
                <option value="option3" <?if ($main_topic == "option3") print selected?>>option3</option>
              </select>
            </form>
          </body>
        </html>
        May that help

        Comment

        Working...